Help: inline .ui files

bookmarkdialog.ui
topicchooser.ui

Change-Id: Ic5c36db648a56546ecf12ce2cb31a593732e7990
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Alessandro Portale
2022-08-15 16:14:05 +02:00
parent fe9de4e205
commit d0f134aa49
12 changed files with 156 additions and 301 deletions

View File

@@ -49,7 +49,9 @@
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QSettings>
#include <QSpinBox>
#include <QTextStream>

View File

@@ -81,12 +81,11 @@ Project {
name: "Shared Sources"
prefix: project.sharedSourcesDir + "/help/"
files: [
"bookmarkdialog.ui",
"bookmarkmanager.cpp", "bookmarkmanager.h",
"contentwindow.cpp", "contentwindow.h",
"helpicons.h",
"indexwindow.cpp", "indexwindow.h",
"topicchooser.cpp", "topicchooser.h", "topicchooser.ui",
"topicchooser.cpp", "topicchooser.h",
]
}
}

View File

@@ -74,9 +74,12 @@
#include <utils/theme/theme.h>
#include <utils/tooltip/tooltip.h>
#include <QApplication>
#include <QDialog>
#include <QDialogButtonBox>
#include <QDir>
#include <QFileInfo>
#include <QLabel>
#include <QLibraryInfo>
#include <QPlainTextEdit>
#include <QTimer>

View File

@@ -53,8 +53,10 @@
#include <utils/styledbar.h>
#include <utils/utilsicons.h>
#include <QComboBox>
#include <QCoreApplication>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QPrintDialog>
#include <QPrinter>

View File

@@ -31,7 +31,7 @@
#include <utils/utilsicons.h>
#include <QCoreApplication>
#include <QApplication>
using namespace Help::Internal;

View File

@@ -20,10 +20,9 @@ add_qtc_library(shared_help STATIC
"${CMAKE_CURRENT_BINARY_DIR}/"
"${CMAKE_CURRENT_LIST_DIR}"
SOURCES
bookmarkdialog.ui
bookmarkmanager.cpp bookmarkmanager.h
contentwindow.cpp contentwindow.h
helpicons.h
indexwindow.cpp indexwindow.h
topicchooser.cpp topicchooser.h topicchooser.ui
topicchooser.cpp topicchooser.h
)

View File

@@ -1,147 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BookmarkDialog</class>
<widget class="QDialog" name="BookmarkDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>450</width>
<height>135</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Add Bookmark</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Bookmark:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Add in folder:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="bookmarkEdit"/>
</item>
<item>
<widget class="QComboBox" name="bookmarkFolders"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QToolButton" name="toolButton">
<property name="minimumSize">
<size>
<width>25</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="treeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="newFolderButton">
<property name="text">
<string>New Folder</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>BookmarkDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>BookmarkDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -30,6 +30,7 @@
#include <coreplugin/icore.h>
#include <utils/fancylineedit.h>
#include <utils/layoutbuilder.h>
#include <utils/styledbar.h>
#include <utils/utilsicons.h>
@@ -65,12 +66,8 @@ BookmarkDialog::BookmarkDialog(BookmarkManager *manager, const QString &title,
, bookmarkManager(manager)
{
installEventFilter(this);
ui.setupUi(this);
ui.bookmarkEdit->setText(title);
ui.newFolderButton->setVisible(false);
ui.buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
resize(450, 0);
setWindowTitle(tr("Add Bookmark"));
proxyModel = new QSortFilterProxyModel(this);
proxyModel->setFilterKeyColumn(0);
@@ -78,30 +75,60 @@ BookmarkDialog::BookmarkDialog(BookmarkManager *manager, const QString &title,
proxyModel->setFilterRole(Qt::UserRole + 10);
proxyModel->setSourceModel(bookmarkManager->treeBookmarkModel());
proxyModel->setFilterRegularExpression(QRegularExpression(QLatin1String("Folder")));
ui.treeView->setModel(proxyModel);
ui.treeView->expandAll();
ui.treeView->setVisible(false);
ui.treeView->header()->setVisible(false);
ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu);
m_bookmarkEdit = new QLineEdit(title);
m_bookmarkFolders = new QComboBox;
m_bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &BookmarkDialog::reject);
connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &BookmarkDialog::addAccepted);
connect(ui.newFolderButton, &QPushButton::clicked, this, &BookmarkDialog::addNewFolder);
connect(ui.toolButton, &QToolButton::clicked, this, &BookmarkDialog::toolButtonClicked);
connect(ui.bookmarkEdit, &QLineEdit::textChanged, this, &BookmarkDialog::textChanged);
m_toolButton = new QToolButton;
m_toolButton->setFixedSize(24, 24);
auto line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
line->setForegroundRole(QPalette::Midlight);
m_treeView = new QTreeView;
m_treeView->setModel(proxyModel);
m_treeView->expandAll();
m_treeView->header()->setVisible(false);
m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
QSizePolicy treeViewSP(QSizePolicy::Preferred, QSizePolicy::Ignored);
treeViewSP.setVerticalStretch(1);
m_treeView->setSizePolicy(treeViewSP);
m_newFolderButton = new QPushButton(tr("New Folder"));
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
using namespace Utils::Layouting;
Column {
Form {
tr("Bookmark:"), m_bookmarkEdit, br,
tr("Add in folder:"), m_bookmarkFolders, br,
},
Row { m_toolButton, line, },
m_treeView,
Row { m_newFolderButton, m_buttonBox, }
}.attachTo(this);
toggleExpanded();
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &BookmarkDialog::reject);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &BookmarkDialog::addAccepted);
connect(m_newFolderButton, &QPushButton::clicked, this, &BookmarkDialog::addNewFolder);
connect(m_toolButton, &QToolButton::clicked, this, &BookmarkDialog::toggleExpanded);
connect(m_bookmarkEdit, &QLineEdit::textChanged, this, &BookmarkDialog::textChanged);
connect(bookmarkManager->treeBookmarkModel(),
&QStandardItemModel::itemChanged,
this, &BookmarkDialog::itemChanged);
connect(ui.bookmarkFolders, &QComboBox::currentIndexChanged,
connect(m_bookmarkFolders, &QComboBox::currentIndexChanged,
this, &BookmarkDialog::selectBookmarkFolder);
connect(ui.treeView, &TreeView::customContextMenuRequested,
connect(m_treeView, &TreeView::customContextMenuRequested,
this, &BookmarkDialog::showContextMenu);
connect(ui.treeView->selectionModel(), &QItemSelectionModel::currentChanged,
connect(m_treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &BookmarkDialog::currentChanged);
}
@@ -111,20 +138,20 @@ BookmarkDialog::~BookmarkDialog()
void BookmarkDialog::addAccepted()
{
QItemSelectionModel *model = ui.treeView->selectionModel();
QItemSelectionModel *model = m_treeView->selectionModel();
const QModelIndexList &list = model->selection().indexes();
QModelIndex index;
if (!list.isEmpty())
index = proxyModel->mapToSource(list.at(0));
bookmarkManager->addNewBookmark(index, ui.bookmarkEdit->text(), m_url);
bookmarkManager->addNewBookmark(index, m_bookmarkEdit->text(), m_url);
accept();
}
void BookmarkDialog::addNewFolder()
{
QItemSelectionModel *model = ui.treeView->selectionModel();
QItemSelectionModel *model = m_treeView->selectionModel();
const QModelIndexList &list = model->selection().indexes();
QModelIndex index;
@@ -134,32 +161,29 @@ void BookmarkDialog::addNewFolder()
QModelIndex newFolder =
bookmarkManager->addNewFolder(proxyModel->mapToSource(index));
if (newFolder.isValid()) {
ui.treeView->expand(index);
m_treeView->expand(index);
const QModelIndex &index = proxyModel->mapFromSource(newFolder);
model->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
ui.bookmarkFolders->clear();
ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
m_bookmarkFolders->clear();
m_bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
const QString &name = index.data().toString();
ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name));
m_bookmarkFolders->setCurrentIndex(m_bookmarkFolders->findText(name));
}
ui.treeView->setFocus();
m_treeView->setFocus();
}
void BookmarkDialog::toolButtonClicked()
void BookmarkDialog::toggleExpanded()
{
bool visible = !ui.treeView->isVisible();
ui.treeView->setVisible(visible);
ui.newFolderButton->setVisible(visible);
if (visible) {
resize(QSize(width(), 400));
ui.toolButton->setText(QLatin1String("-"));
} else {
resize(width(), minimumHeight());
ui.toolButton->setText(QLatin1String("+"));
}
const char expand[] = "+";
const char collapse[] = "-";
const bool doCollapse = m_toolButton->text() != expand;
m_toolButton->setText(doCollapse ? expand : collapse);
m_treeView->setVisible(!doCollapse);
m_newFolderButton->setVisible(!doCollapse);
for (int i = 0; i <= 1; ++i) // Hack: resize twice to avoid "jumping" of m_toolButton
resize(width(), (doCollapse ? 1 : 400));
}
void BookmarkDialog::itemChanged(QStandardItem *item)
@@ -171,27 +195,27 @@ void BookmarkDialog::itemChanged(QStandardItem *item)
}
if (item->text() != oldText) {
ui.bookmarkFolders->clear();
ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
m_bookmarkFolders->clear();
m_bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
QString name = tr("Bookmarks");
const QModelIndex& index = ui.treeView->currentIndex();
const QModelIndex& index = m_treeView->currentIndex();
if (index.isValid())
name = index.data().toString();
ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name));
m_bookmarkFolders->setCurrentIndex(m_bookmarkFolders->findText(name));
}
}
void BookmarkDialog::textChanged(const QString& string)
{
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!string.isEmpty());
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!string.isEmpty());
}
void BookmarkDialog::selectBookmarkFolder(int index)
{
const QString folderName = ui.bookmarkFolders->itemText(index);
const QString folderName = m_bookmarkFolders->itemText(index);
if (folderName == tr("Bookmarks")) {
ui.treeView->clearSelection();
m_treeView->clearSelection();
return;
}
@@ -200,7 +224,7 @@ void BookmarkDialog::selectBookmarkFolder(int index)
Qt::MatchCaseSensitive | Qt::MatchRecursive, 0);
if (!list.isEmpty()) {
const QModelIndex &index = model->indexFromItem(list.at(0));
QItemSelectionModel *model = ui.treeView->selectionModel();
QItemSelectionModel *model = m_treeView->selectionModel();
if (model) {
model->setCurrentIndex(proxyModel->mapFromSource(index),
QItemSelectionModel::ClearAndSelect);
@@ -210,7 +234,7 @@ void BookmarkDialog::selectBookmarkFolder(int index)
void BookmarkDialog::showContextMenu(const QPoint &point)
{
QModelIndex index = ui.treeView->indexAt(point);
QModelIndex index = m_treeView->indexAt(point);
if (!index.isValid())
return;
@@ -219,26 +243,26 @@ void BookmarkDialog::showContextMenu(const QPoint &point)
QAction *removeItem = menu.addAction(tr("Delete Folder"));
QAction *renameItem = menu.addAction(tr("Rename Folder"));
QAction *picked = menu.exec(ui.treeView->mapToGlobal(point));
QAction *picked = menu.exec(m_treeView->mapToGlobal(point));
if (!picked)
return;
const QModelIndex &proxyIndex = proxyModel->mapToSource(index);
if (picked == removeItem) {
bookmarkManager->removeBookmarkItem(ui.treeView, proxyIndex);
ui.bookmarkFolders->clear();
ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
bookmarkManager->removeBookmarkItem(m_treeView, proxyIndex);
m_bookmarkFolders->clear();
m_bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
QString name = tr("Bookmarks");
index = ui.treeView->currentIndex();
index = m_treeView->currentIndex();
if (index.isValid())
name = index.data().toString();
ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name));
m_bookmarkFolders->setCurrentIndex(m_bookmarkFolders->findText(name));
} else if (picked == renameItem) {
BookmarkModel *model = bookmarkManager->treeBookmarkModel();
if (QStandardItem *item = model->itemFromIndex(proxyIndex)) {
item->setEditable(true);
ui.treeView->edit(index);
m_treeView->edit(index);
item->setEditable(false);
}
}
@@ -249,7 +273,7 @@ void BookmarkDialog::currentChanged(const QModelIndex &current)
QString text = tr("Bookmarks");
if (current.isValid())
text = current.data().toString();
ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(text));
m_bookmarkFolders->setCurrentIndex(m_bookmarkFolders->findText(text));
}
bool BookmarkDialog::eventFilter(QObject *object, QEvent *e)
@@ -257,7 +281,7 @@ bool BookmarkDialog::eventFilter(QObject *object, QEvent *e)
if (object == this && e->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent*>(e);
QModelIndex index = ui.treeView->currentIndex();
QModelIndex index = m_treeView->currentIndex();
switch (ke->key()) {
case Qt::Key_F2: {
const QModelIndex &source = proxyModel->mapToSource(index);
@@ -265,23 +289,23 @@ bool BookmarkDialog::eventFilter(QObject *object, QEvent *e)
bookmarkManager->treeBookmarkModel()->itemFromIndex(source);
if (item) {
item->setEditable(true);
ui.treeView->edit(index);
m_treeView->edit(index);
item->setEditable(false);
}
} break;
case Qt::Key_Backspace:
case Qt::Key_Delete: {
bookmarkManager->removeBookmarkItem(ui.treeView,
bookmarkManager->removeBookmarkItem(m_treeView,
proxyModel->mapToSource(index));
ui.bookmarkFolders->clear();
ui.bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
m_bookmarkFolders->clear();
m_bookmarkFolders->addItems(bookmarkManager->bookmarkFolders());
QString name = tr("Bookmarks");
index = ui.treeView->currentIndex();
index = m_treeView->currentIndex();
if (index.isValid())
name = index.data().toString();
ui.bookmarkFolders->setCurrentIndex(ui.bookmarkFolders->findText(name));
m_bookmarkFolders->setCurrentIndex(m_bookmarkFolders->findText(name));
} break;
default:

View File

@@ -25,8 +25,6 @@
#pragma once
#include "ui_bookmarkdialog.h"
#include <utils/navigationtreeview.h>
#include <QUrl>
@@ -42,8 +40,11 @@
#include <QStandardItemModel>
QT_BEGIN_NAMESPACE
class QComboBox;
class QDialogButtonBox;
class QEvent;
class QLineEdit;
class QPushButton;
class QTreeView;
class QToolButton;
class QStandardItem;
@@ -67,7 +68,7 @@ public:
private:
void addAccepted();
void addNewFolder();
void toolButtonClicked();
void toggleExpanded();
void itemChanged(QStandardItem *item);
void textChanged(const QString& string);
void selectBookmarkFolder(int index);
@@ -81,9 +82,15 @@ private:
QString oldText;
QStandardItem *renameItem;
Ui::BookmarkDialog ui;
BookmarkManager *bookmarkManager;
QSortFilterProxyModel *proxyModel;
QLineEdit *m_bookmarkEdit;
QDialogButtonBox *m_buttonBox;
QComboBox *m_bookmarkFolders;
QPushButton *m_newFolderButton;
QTreeView *m_treeView;
QToolButton *m_toolButton;
};
class TreeView : public Utils::NavigationTreeView

View File

@@ -25,10 +25,15 @@
#include "topicchooser.h"
#include <utils/layoutbuilder.h>
#include <utils/fancylineedit.h>
#include <QMap>
#include <QUrl>
#include <QKeyEvent>
#include <QDialogButtonBox>
#include <QListView>
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
@@ -37,13 +42,8 @@ TopicChooser::TopicChooser(QWidget *parent, const QString &keyword,
: QDialog(parent)
, m_filterModel(new QSortFilterProxyModel(this))
{
ui.setupUi(this);
setFocusProxy(ui.lineEdit);
ui.lineEdit->setFiltering(true);
ui.lineEdit->installEventFilter(this);
ui.lineEdit->setPlaceholderText(tr("Filter"));
ui.label->setText(tr("Choose a topic for <b>%1</b>:").arg(keyword));
resize(400, 220);
setWindowTitle(tr("Choose Topic"));
QStandardItemModel *model = new QStandardItemModel(this);
m_filterModel->setSourceModel(model);
@@ -57,20 +57,35 @@ TopicChooser::TopicChooser(QWidget *parent, const QString &keyword,
model->appendRow(item);
}
ui.listWidget->setModel(m_filterModel);
ui.listWidget->setUniformItemSizes(true);
ui.listWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_lineEdit = new Utils::FancyLineEdit;
m_lineEdit->setFiltering(true);
m_lineEdit->installEventFilter(this);
setFocusProxy(m_lineEdit);
m_listWidget = new QListView;
m_listWidget->setModel(m_filterModel);
m_listWidget->setUniformItemSizes(true);
m_listWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
if (m_filterModel->rowCount() != 0)
ui.listWidget->setCurrentIndex(m_filterModel->index(0, 0));
m_listWidget->setCurrentIndex(m_filterModel->index(0, 0));
connect(ui.buttonBox, &QDialogButtonBox::accepted,
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
using namespace Utils::Layouting;
Column {
tr("Choose a topic for <b>%1</b>:").arg(keyword),
m_lineEdit,
m_listWidget,
buttonBox,
}.attachTo(this);
connect(buttonBox, &QDialogButtonBox::accepted,
this, &TopicChooser::acceptDialog);
connect(ui.buttonBox, &QDialogButtonBox::rejected,
connect(buttonBox, &QDialogButtonBox::rejected,
this, &TopicChooser::reject);
connect(ui.listWidget, &QListView::activated,
connect(m_listWidget, &QListView::activated,
this, &TopicChooser::activated);
connect(ui.lineEdit, &Utils::FancyLineEdit::filterChanged,
connect(m_lineEdit, &Utils::FancyLineEdit::filterChanged,
this, &TopicChooser::setFilter);
}
@@ -83,15 +98,15 @@ QUrl TopicChooser::link() const
void TopicChooser::acceptDialog()
{
m_activedIndex = ui.listWidget->currentIndex();
m_activedIndex = m_listWidget->currentIndex();
accept();
}
void TopicChooser::setFilter(const QString &pattern)
{
m_filterModel->setFilterFixedString(pattern);
if (m_filterModel->rowCount() != 0 && !ui.listWidget->currentIndex().isValid())
ui.listWidget->setCurrentIndex(m_filterModel->index(0, 0));
if (m_filterModel->rowCount() != 0 && !m_listWidget->currentIndex().isValid())
m_listWidget->setCurrentIndex(m_filterModel->index(0, 0));
}
void TopicChooser::activated(const QModelIndex &index)
@@ -102,7 +117,7 @@ void TopicChooser::activated(const QModelIndex &index)
bool TopicChooser::eventFilter(QObject *object, QEvent *event)
{
if (object == ui.lineEdit && event->type() == QEvent::KeyPress) {
if (object == m_lineEdit && event->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
int dIndex = 0;
switch (ke->key()) {
@@ -122,18 +137,18 @@ bool TopicChooser::eventFilter(QObject *object, QEvent *event)
break;
}
if (dIndex != 0) {
QModelIndex idx = ui.listWidget->currentIndex();
QModelIndex idx = m_listWidget->currentIndex();
int newIndex = qMin(m_filterModel->rowCount(idx.parent()) - 1,
qMax(0, idx.row() + dIndex));
idx = m_filterModel->index(newIndex, idx.column(), idx.parent());
if (idx.isValid())
ui.listWidget->setCurrentIndex(idx);
m_listWidget->setCurrentIndex(idx);
return true;
}
} else if (ui.lineEdit && event->type() == QEvent::FocusIn
} else if (m_lineEdit && event->type() == QEvent::FocusIn
&& static_cast<QFocusEvent *>(event)->reason() != Qt::MouseFocusReason) {
ui.lineEdit->selectAll();
ui.lineEdit->setFocus();
m_lineEdit->selectAll();
m_lineEdit->setFocus();
}
return QDialog::eventFilter(object, event);
}

View File

@@ -25,8 +25,6 @@
#pragma once
#include "ui_topicchooser.h"
#include <QUrl>
#include <QMap>
#include <QModelIndex>
@@ -34,7 +32,12 @@
#include <QDialog>
QT_FORWARD_DECLARE_CLASS(QSortFilterProxyModel)
QT_BEGIN_NAMESPACE
class QListView;
class QSortFilterProxyModel;
QT_END_NAMESPACE
namespace Utils { class FancyLineEdit; }
class TopicChooser : public QDialog
{
@@ -52,9 +55,11 @@ private:
void activated(const QModelIndex &index);
bool eventFilter(QObject *object, QEvent *event) override;
Ui::TopicChooser ui;
QList<QUrl> m_links;
QModelIndex m_activedIndex;
QSortFilterProxyModel *m_filterModel;
Utils::FancyLineEdit *m_lineEdit;
QListView *m_listWidget;
};

View File

@@ -1,54 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TopicChooser</class>
<widget class="QDialog" name="TopicChooser">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>393</width>
<height>218</height>
</rect>
</property>
<property name="windowTitle">
<string>Choose Topic</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Topics</string>
</property>
<property name="buddy">
<cstring>listWidget</cstring>
</property>
</widget>
</item>
<item>
<widget class="Utils::FancyLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QListView" name="listWidget"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::FancyLineEdit</class>
<extends>QLineEdit</extends>
<header location="global">utils/fancylineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>