From d50b66fc883a1321159afc365c0dfcd8b45c80b8 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Sun, 26 Feb 2017 22:15:50 +0100 Subject: [PATCH] Whitespace and remove obsolete #ifdef. --- src/frontends/qt4/FancyLineEdit.cpp | 21 +++++--- src/frontends/qt4/FancyLineEdit.h | 78 +++++++++++++-------------- src/frontends/qt4/PanelStack.cpp | 82 ++++++++++++++++++----------- 3 files changed, 104 insertions(+), 77 deletions(-) diff --git a/src/frontends/qt4/FancyLineEdit.cpp b/src/frontends/qt4/FancyLineEdit.cpp index 118a9b876f..0e35ebb6ce 100644 --- a/src/frontends/qt4/FancyLineEdit.cpp +++ b/src/frontends/qt4/FancyLineEdit.cpp @@ -104,9 +104,12 @@ FancyLineEdit::FancyLineEdit(QWidget *parent) : ensurePolished(); updateMargins(); - connect(this, SIGNAL(textChanged(QString)), this, SLOT(checkButtons(QString))); - connect(m_d->m_iconbutton[Left], SIGNAL(clicked()), this, SLOT(iconClicked())); - connect(m_d->m_iconbutton[Right], SIGNAL(clicked()), this, SLOT(iconClicked())); + connect(this, SIGNAL(textChanged(QString)), + this, SLOT(checkButtons(QString))); + connect(m_d->m_iconbutton[Left], SIGNAL(clicked()), + this, SLOT(iconClicked())); + connect(m_d->m_iconbutton[Right], SIGNAL(clicked()), + this, SLOT(iconClicked())); } void FancyLineEdit::checkButtons(const QString &text) @@ -186,10 +189,12 @@ void FancyLineEdit::updateButtonPositions() if (iconpos == FancyLineEdit::Right) { const int iconoffset = textMargins().right() + 4; - m_d->m_iconbutton[i]->setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0)); + m_d->m_iconbutton[i]-> + setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0)); } else { const int iconoffset = textMargins().left() + 4; - m_d->m_iconbutton[i]->setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0)); + m_d->m_iconbutton[i]-> + setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0)); } } } @@ -295,12 +300,14 @@ void IconButton::paintEvent(QPaintEvent *) void IconButton::animateShow(bool visible) { if (visible) { - QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity"); + QPropertyAnimation *animation = + new QPropertyAnimation(this, "iconOpacity"); animation->setDuration(FADE_TIME); animation->setEndValue(1.0); animation->start(QAbstractAnimation::DeleteWhenStopped); } else { - QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity"); + QPropertyAnimation *animation = + new QPropertyAnimation(this, "iconOpacity"); animation->setDuration(FADE_TIME); animation->setEndValue(0.0); animation->start(QAbstractAnimation::DeleteWhenStopped); diff --git a/src/frontends/qt4/FancyLineEdit.h b/src/frontends/qt4/FancyLineEdit.h index cd3c6b5951..ef6b45aa5f 100644 --- a/src/frontends/qt4/FancyLineEdit.h +++ b/src/frontends/qt4/FancyLineEdit.h @@ -29,20 +29,20 @@ class IconButton: public QAbstractButton Q_PROPERTY(bool autoHide READ hasAutoHide WRITE setAutoHide) Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) public: - explicit IconButton(QWidget *parent = 0); - void paintEvent(QPaintEvent *event); - void setPixmap(const QPixmap &pixmap) { m_pixmap = pixmap; update(); } - QPixmap pixmap() const { return m_pixmap; } - float iconOpacity() { return m_iconOpacity; } - void setIconOpacity(float value) { m_iconOpacity = value; update(); } - void animateShow(bool visible); - - void setAutoHide(bool hide) { m_autoHide = hide; } - bool hasAutoHide() const { return m_autoHide; } + explicit IconButton(QWidget *parent = 0); + void paintEvent(QPaintEvent *event); + void setPixmap(const QPixmap &pixmap) { m_pixmap = pixmap; update(); } + QPixmap pixmap() const { return m_pixmap; } + float iconOpacity() { return m_iconOpacity; } + void setIconOpacity(float value) { m_iconOpacity = value; update(); } + void animateShow(bool visible); + + void setAutoHide(bool hide) { m_autoHide = hide; } + bool hasAutoHide() const { return m_autoHide; } private: - float m_iconOpacity; - bool m_autoHide; - QPixmap m_pixmap; + float m_iconOpacity; + bool m_autoHide; + QPixmap m_pixmap; }; /* A line edit with an embedded pixmap on one side that is connected to @@ -59,52 +59,52 @@ class FancyLineEdit : public QLineEdit Q_ENUMS(Side) public: - enum Side {Left = 0, Right = 1}; + enum Side {Left = 0, Right = 1}; Q_SIGNALS: - void buttonClicked(Side side); - void leftButtonClicked(); - void rightButtonClicked(); + void buttonClicked(Side side); + void leftButtonClicked(); + void rightButtonClicked(); void downPressed(); public: - explicit FancyLineEdit(QWidget *parent = 0); - ~FancyLineEdit(); + explicit FancyLineEdit(QWidget *parent = 0); + ~FancyLineEdit(); - QPixmap buttonPixmap(Side side) const; - void setButtonPixmap(Side side, const QPixmap &pixmap); + QPixmap buttonPixmap(Side side) const; + void setButtonPixmap(Side side, const QPixmap &pixmap); - QMenu *buttonMenu(Side side) const; - void setButtonMenu(Side side, QMenu *menu); + QMenu *buttonMenu(Side side) const; + void setButtonMenu(Side side, QMenu *menu); - void setButtonVisible(Side side, bool visible); - bool isButtonVisible(Side side) const; + void setButtonVisible(Side side, bool visible); + bool isButtonVisible(Side side) const; - void setButtonToolTip(Side side, const QString &); - void setButtonFocusPolicy(Side side, Qt::FocusPolicy policy); + void setButtonToolTip(Side side, const QString &); + void setButtonFocusPolicy(Side side, Qt::FocusPolicy policy); - // Set whether tabbing in will trigger the menu. - void setMenuTabFocusTrigger(Side side, bool v); - bool hasMenuTabFocusTrigger(Side side) const; + // Set whether tabbing in will trigger the menu. + void setMenuTabFocusTrigger(Side side, bool v); + bool hasMenuTabFocusTrigger(Side side) const; - // Set if icon should be hidden when text is empty - void setAutoHideButton(Side side, bool h); - bool hasAutoHideButton(Side side) const; + // Set if icon should be hidden when text is empty + void setAutoHideButton(Side side, bool h); + bool hasAutoHideButton(Side side) const; private Q_SLOTS: - void checkButtons(const QString &); - void iconClicked(); + void checkButtons(const QString &); + void iconClicked(); protected: - virtual void resizeEvent(QResizeEvent *e); + virtual void resizeEvent(QResizeEvent *e); virtual void keyPressEvent(QKeyEvent *e); private: - void updateMargins(); + void updateMargins(); void updateButtonPositions(); - FancyLineEditPrivate *m_d; - QString m_oldText; + FancyLineEditPrivate *m_d; + QString m_oldText; }; } diff --git a/src/frontends/qt4/PanelStack.cpp b/src/frontends/qt4/PanelStack.cpp index d708952797..63bc07347f 100644 --- a/src/frontends/qt4/PanelStack.cpp +++ b/src/frontends/qt4/PanelStack.cpp @@ -63,29 +63,28 @@ PanelStack::PanelStack(QWidget * parent) 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 - -#if QT_VERSION >= 0x040600 - search_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,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); -#endif - connect(search_, SIGNAL(rightButtonClicked()), this, SLOT(resetSearch())); - connect(search_, SIGNAL(textEdited(QString)), this, SLOT(filterChanged(QString))); + 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 + // 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); @@ -120,7 +119,7 @@ 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(qt_(name)) + 10 + list_->indentation() * depth; // adjust the listview width to the max. itemsize @@ -129,7 +128,8 @@ void PanelStack::addCategory(QString const & name, QString const & parent) } -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); @@ -210,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) @@ -254,7 +256,8 @@ void PanelStack::search() 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) { @@ -263,30 +266,45 @@ void PanelStack::search() 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; @@ -299,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 @@ -309,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); -- 2.39.2