X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FPanelStack.cpp;h=63bc07347f8d54c06cf6f76ce26863eb7e92527b;hb=1f10969bb5c5f36017bf5ba8671381b09945cf57;hp=1863040bd19d107b3dda132e1a2e353dc1ec0a89;hpb=519f74ab61e4b86b11c252dc9f24d503adf0e571;p=lyx.git diff --git a/src/frontends/qt4/PanelStack.cpp b/src/frontends/qt4/PanelStack.cpp index 1863040bd1..63bc07347f 100644 --- a/src/frontends/qt4/PanelStack.cpp +++ b/src/frontends/qt4/PanelStack.cpp @@ -16,12 +16,10 @@ #include "qt_helpers.h" #include "support/debug.h" -#include "support/foreach.h" #include "support/lassert.h" #include #include -#include #include #include #include @@ -49,9 +47,9 @@ PanelStack::PanelStack(QWidget * parent) : QWidget(parent) { delay_search_ = new QTimer(this); + search_ = new FancyLineEdit(this); list_ = new QTreeWidget(this); stack_ = new QStackedWidget(this); - search_ = new FancyLineEdit(this); // Configure the timer delay_search_->setSingleShot(true); @@ -61,30 +59,33 @@ PanelStack::PanelStack(QWidget * parent) list_->setRootIsDecorated(false); list_->setColumnCount(1); list_->header()->hide(); - list_->header()->setResizeMode(QHeaderView::ResizeToContents); + setSectionResizeMode(list_->header(), QHeaderView::ResizeToContents); list_->header()->setStretchLastSection(false); list_->setMinimumSize(list_->viewport()->size()); - connect(list_, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), + connect(list_, SIGNAL(currentItemChanged(QTreeWidgetItem*, + QTreeWidgetItem*)), this, SLOT(switchPanel(QTreeWidgetItem *, QTreeWidgetItem*))); connect(list_, SIGNAL(itemClicked (QTreeWidgetItem*, int)), this, SLOT(itemSelected(QTreeWidgetItem *, int))); // Configure the search box -#if QT_VERSION >= 0x040700 search_->setPlaceholderText(qt_("Search")); -#endif - - search_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "png")); + search_->setButtonPixmap(FancyLineEdit::Right, + getPixmap("images/", "editclear", "svgz,png")); search_->setButtonVisible(FancyLineEdit::Right, true); search_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text")); search_->setAutoHideButton(FancyLineEdit::Right, true); - connect(search_, SIGNAL(rightButtonClicked()), this, SLOT(resetSearch())); - connect(search_, SIGNAL(textEdited(QString)), this, SLOT(filterChanged(QString))); - - // Create the output layout, horizontal plus a VBox on the left with the search - // box and the tree - QVBoxLayout * left_layout = new QVBoxLayout(); + connect(search_, SIGNAL(rightButtonClicked()), + this, SLOT(resetSearch())); + connect(search_, SIGNAL(textEdited(QString)), + this, SLOT(filterChanged(QString))); + connect(search_, SIGNAL(downPressed()), + list_, SLOT(setFocus())); + + // Create the output layout, horizontal plus a VBox on the left with the + // search box and the tree + QVBoxLayout * left_layout = new QVBoxLayout; left_layout->addWidget(search_, 0); left_layout->addWidget(list_, 1); @@ -104,13 +105,13 @@ void PanelStack::addCategory(QString const & name, QString const & parent) if (parent.isEmpty()) { item = new QTreeWidgetItem(list_); - item->setText(0, name); + item->setText(0, qt_(name)); } else { if (!panel_map_.contains(parent)) addCategory(parent); item = new QTreeWidgetItem(panel_map_.value(parent)); - item->setText(0, name); + item->setText(0, qt_(name)); depth = 2; list_->setRootIsDecorated(true); } @@ -118,16 +119,17 @@ void PanelStack::addCategory(QString const & name, QString const & parent) panel_map_[name] = item; QFontMetrics fm(list_->font()); - + // calculate the real size the current item needs in the listview - int itemsize = fm.width(name) + 10 + list_->indentation() * depth; + int itemsize = fm.width(qt_(name)) + 10 + list_->indentation() * depth; // adjust the listview width to the max. itemsize if (itemsize > list_->minimumWidth()) list_->setMinimumWidth(itemsize); } -void PanelStack::addPanel(QWidget * panel, QString const & name, QString const & parent) +void PanelStack::addPanel(QWidget * panel, QString const & name, + QString const & parent) { addCategory(name, parent); QTreeWidgetItem * item = panel_map_.value(name); @@ -208,8 +210,10 @@ static void setTreeItemStatus(QTreeWidgetItem * tree_item, bool enabled) tree_item->setDisabled(!enabled); // Change the color from black to gray or viceversa - QPalette::ColorGroup new_color = enabled ? QPalette::Active : QPalette::Disabled; - tree_item->setTextColor(0, QApplication::palette().color(new_color, QPalette::Text)); + QPalette::ColorGroup new_color = + enabled ? QPalette::Active : QPalette::Disabled; + tree_item->setTextColor(0, QApplication::palette().color(new_color, + QPalette::Text)); } void PanelStack::hideEvent(QHideEvent * event) @@ -243,48 +247,64 @@ void PanelStack::search() // If the search string is empty we enable all the items // otherwise we disable everything and then selectively // re-enable matching items - foreach (QTreeWidgetItem * tree_item, panel_map_) { + for (QTreeWidgetItem * tree_item : panel_map_) { setTreeItemStatus(tree_item, enable_all); } - foreach (QTreeWidgetItem * tree_item, panel_map_) { + for (QTreeWidgetItem * tree_item : panel_map_) { // Current widget QWidget * pane_widget = widget_map_[tree_item]; // First of all we look in the pane name - bool pane_matches = tree_item->text(0).contains(search, Qt::CaseInsensitive); + bool pane_matches = tree_item->text(0).contains(search, + Qt::CaseInsensitive); // If the tree item has an associated pane if (pane_widget) { // Loops on the list of children widgets (recursive) QWidgetList children = pane_widget->findChildren(); - foreach (QWidget * child_widget, children) { + for (QWidget * child_widget : children) { bool widget_matches = false; - // Try to cast to the most common widgets and looks in it's content - // It's bad OOP, it would be nice to have a QWidget::toString() overloaded by - // each widget, but this would require to change Qt or subclass each widget. + // Try to cast to the most common widgets and looks in it's + // content. + // It's bad OOP, it would be nice to have a QWidget::toString() + // overloaded by each widget, but this would require to change + // Qt or subclass each widget. // Note that we have to ignore the amperstand symbol - if (QAbstractButton * button = qobject_cast(child_widget)) { + if (QAbstractButton * button = + qobject_cast(child_widget)) { widget_matches = matches(button->text(), search); - } else if (QGroupBox * group_box = qobject_cast(child_widget)) { + } else if (QGroupBox * group_box = + qobject_cast(child_widget)) { widget_matches = matches(group_box->title(), search); - } else if (QLabel * label = qobject_cast(child_widget)) { + } else if (QLabel * label = + qobject_cast(child_widget)) { widget_matches = matches(label->text(), search); - } else if (QLineEdit * line_edit = qobject_cast(child_widget)) { + } else if (QLineEdit * line_edit = + qobject_cast(child_widget)) { widget_matches = matches(line_edit->text(), search); - } else if (QListWidget * list_widget = qobject_cast(child_widget)) { - widget_matches = (list_widget->findItems(search, Qt::MatchContains)).count() > 0; + } else if (QListWidget * list_widget = + qobject_cast(child_widget)) { + widget_matches = + list_widget->findItems(search, + Qt::MatchContains).count() > 0; - } else if (QTreeWidget * tree_view = qobject_cast(child_widget)) { - widget_matches = (tree_view->findItems(search, Qt::MatchContains)).count() > 0; + } else if (QTreeWidget * tree_view = + qobject_cast(child_widget)) { + widget_matches = + tree_view->findItems(search, + Qt::MatchContains).count() > 0; - } else if (QComboBox * combo_box = qobject_cast(child_widget)) { - widget_matches = (combo_box->findText(search, Qt::MatchContains)) != -1; + } else if (QComboBox * combo_box = + qobject_cast(child_widget)) { + widget_matches = + combo_box->findText(search, + Qt::MatchContains) != -1; } else { continue; @@ -297,7 +317,8 @@ void PanelStack::search() // Highlight the widget QPalette widget_palette = child_widget->palette(); - widget_palette.setColor(child_widget->foregroundRole(), Qt::red); + widget_palette.setColor(child_widget->foregroundRole(), + Qt::red); child_widget->setPalette(widget_palette); } else { // Reset the color of the widget @@ -307,7 +328,8 @@ void PanelStack::search() // If the pane meets the search criteria if (pane_matches && !enable_all) { - // Expand and enable the pane and his ancestors (typically just the parent) + // Expand and enable the pane and his ancestors (typically just + // the parent) QTreeWidgetItem * item = tree_item; do { item->setExpanded(true);