Added tooltips and filter to menu customization dialog

This commit is contained in:
Matthias Koefferlein 2017-11-05 09:23:24 +01:00
parent dbc5079bb4
commit b5e6423c8d
3 changed files with 127 additions and 34 deletions

View File

@ -19,10 +19,7 @@
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>9</number>
</property>
@ -35,35 +32,7 @@
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QTreeWidget" name="bindings_list">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Path</string>
</property>
</column>
<column>
<property name="text">
<string>Title</string>
</property>
</column>
<column>
<property name="text">
<string>Shortcut</string>
</property>
</column>
</widget>
</item>
<item>
<item row="1" column="1">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
@ -171,6 +140,91 @@ For special keys:
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QTreeWidget" name="bindings_list">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Path</string>
</property>
</column>
<column>
<property name="text">
<string>Title</string>
</property>
</column>
<column>
<property name="text">
<string>Shortcut</string>
</property>
</column>
</widget>
</item>
<item row="0" column="0">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>328</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="layResources.qrc">:/find.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="lay::DecoratedLineEdit" name="filter">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
@ -181,6 +235,8 @@ For special keys:
<header>layWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="layResources.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -408,6 +408,9 @@ CustomizeMenuConfigPage::CustomizeMenuConfigPage (QWidget *parent)
mp_ui->binding_le->setEnabled (false);
mp_ui->binding_le->set_clear_button_enabled (true);
connect (mp_ui->binding_le, SIGNAL (textChanged (QString)), this, SLOT (text_changed ()));
mp_ui->filter->set_clear_button_enabled (true);
connect (mp_ui->filter, SIGNAL (textChanged (QString)), this, SLOT (filter_changed ()));
}
CustomizeMenuConfigPage::~CustomizeMenuConfigPage ()
@ -455,6 +458,11 @@ CustomizeMenuConfigPage::reset_clicked ()
void
CustomizeMenuConfigPage::apply (const std::vector<std::pair<std::string, std::string> > &key_bindings, const std::vector<std::pair<std::string, bool> > &hidden)
{
// clears the filter
mp_ui->filter->blockSignals (true);
mp_ui->filter->clear ();
mp_ui->filter->blockSignals (false);
// build the path to item table and the alias table
m_item_for_path.clear ();
m_paths_for_action.clear ();
@ -532,13 +540,16 @@ CustomizeMenuConfigPage::apply (const std::vector<std::pair<std::string, std::st
if (t->first == tl_menu) {
QTreeWidgetItem *item = new QTreeWidgetItem (top_level_item);
lay::Action action = lay::MainWindow::instance ()->menu ()->action (cb->first);
item->setData (0, Qt::ToolTipRole, tl::to_qstring (rem_path));
item->setData (0, Qt::DisplayRole, tl::to_qstring (rem_path));
item->setData (1, Qt::ToolTipRole, tl::to_qstring (action.get_title ()));
item->setData (1, Qt::DisplayRole, tl::to_qstring (action.get_title ()));
item->setData (2, Qt::DisplayRole, tl::to_qstring (sc));
item->setData (2, Qt::ForegroundRole, palette ().color (is_default ? QPalette::Disabled : QPalette::Normal, QPalette::Text));
item->setData (0, Qt::UserRole, tl::to_qstring (path));
item->setFlags (item->flags () | Qt::ItemIsUserCheckable);
item->setCheckState (0, hidden ? Qt::Unchecked : Qt::Checked);
item->setHidden (false);
m_item_for_path[path] = item;
if (action.qaction ()) {
m_paths_for_action[action.qaction ()].push_back (path);
@ -626,6 +637,31 @@ CustomizeMenuConfigPage::text_changed ()
}
}
void
CustomizeMenuConfigPage::filter_changed ()
{
mp_ui->bindings_list->clearSelection ();
current_changed (0, mp_ui->bindings_list->currentItem ());
QString filter = mp_ui->filter->text ();
for (int i = 0; i < mp_ui->bindings_list->topLevelItemCount (); ++i) {
QTreeWidgetItem *tl_item = mp_ui->bindings_list->topLevelItem (i);
bool any = false;
for (int j = 0; j < tl_item->childCount (); ++j) {
QTreeWidgetItem *item = tl_item->child (j);
QString path = item->data (0, Qt::DisplayRole).toString ();
QString title = item->data (1, Qt::DisplayRole).toString ();
bool matches = path.indexOf (filter, 0, Qt::CaseInsensitive) >= 0 || title.indexOf (filter, 0, Qt::CaseInsensitive) >= 0;
item->setHidden (!matches);
if (matches) {
any = true;
}
}
tl_item->setHidden (!any);
}
}
void
CustomizeMenuConfigPage::update_list_item (QTreeWidgetItem *item)
{

View File

@ -199,6 +199,7 @@ private slots:
void current_changed (QTreeWidgetItem *current, QTreeWidgetItem *previous);
void item_changed (QTreeWidgetItem *, int);
void text_changed ();
void filter_changed ();
void reset_clicked ();
private: