diff options
author | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2015-12-21 13:27:01 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-01-22 16:38:36 +0000 |
commit | ba524dc69fd9e304afba71cbf505d778e4cc92c2 (patch) | |
tree | 51519d2bd8ddb7de7b688a55c899ad7506bdbc81 | |
parent | cec37e10d6b58e1dc180851ffc2302315991b747 (diff) |
bringToFront: support item view items
instead of blatantly assuming that every TranslatableEntry is a widget,
actually check the entry type and use the parent item view (instead of
crashing) if it's an item.
Task-number: QTBUG-50068
Change-Id: I781d00226894f074e2a3eb0bd0db84e7a28231b0
Reviewed-by: Frederic Marchal <frederic.marchal@wowtechnology.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
-rw-r--r-- | src/linguist/linguist/formpreviewview.cpp | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/src/linguist/linguist/formpreviewview.cpp b/src/linguist/linguist/formpreviewview.cpp index 95d986713..1647c3cd8 100644 --- a/src/linguist/linguist/formpreviewview.cpp +++ b/src/linguist/linguist/formpreviewview.cpp @@ -287,6 +287,31 @@ static void retranslateTargets( retranslateTarget(target, text); } +static void bringToFront(QWidget *w) +{ + for (; QWidget *pw = w->parentWidget(); w = pw) { +#ifndef QT_NO_STACKEDWIDGET + if (QStackedWidget *stack = qobject_cast<QStackedWidget *>(pw)) { +#ifndef QT_NO_TABWIDGET + // Updating QTabWidget's embedded QStackedWidget does not update its + // QTabBar, so handle tab widgets explicitly. + if (QTabWidget *tab = qobject_cast<QTabWidget *>(stack->parent())) + tab->setCurrentWidget(w); + else +#endif + stack->setCurrentWidget(w); + continue; + } +#endif +#ifndef QT_NO_TOOLBOX + if (QScrollArea *sv = qobject_cast<QScrollArea *>(pw)) { + if (QToolBox *tb = qobject_cast<QToolBox *>(sv->parent())) + tb->setCurrentWidget(w); + } +#endif + } +} + static void highlightTreeWidgetItem(QTreeWidgetItem *item, int col, bool on) { QVariant br = item->data(col, Qt::BackgroundRole + 500); @@ -395,38 +420,14 @@ static void highlightWidget(QWidget *w, bool on) highlightAction(m->menuAction(), on); } -static void bringToFront(const TranslatableEntry &target) -{ - for (QObject *obj = target.target.object; obj != 0; obj = obj->parent()) { - if (QWidget *w = qobject_cast<QWidget *>(obj)) { -#ifndef QT_NO_STACKEDWIDGET - if (QStackedWidget *stack = qobject_cast<QStackedWidget *>(obj->parent())) { -#ifndef QT_NO_TABWIDGET - // Updating QTabWidget's embedded QStackedWidget does not update its - // QTabBar, so handle tab widgets explicitly. - if (QTabWidget *tab = qobject_cast<QTabWidget *>(stack->parent())) - tab->setCurrentWidget(w); - else -#endif - stack->setCurrentWidget(w); - } -#endif -#ifndef QT_NO_TOOLBOX - if (QScrollArea *sv = qobject_cast<QScrollArea *>(obj->parent())) - if (QToolBox *tb = qobject_cast<QToolBox *>(sv->parent())) - tb->setCurrentWidget(w); -#endif - } - } -} static void highlightTarget(const TranslatableEntry &target, bool on) { - bringToFront(target); switch (target.type) { case TranslatableProperty: if (QAction *a = qobject_cast<QAction *>(target.target.object)) { highlightAction(a, on); } else if (QWidget *w = qobject_cast<QWidget *>(target.target.object)) { + bringToFront(w); highlightWidget(w, on); } break; @@ -448,20 +449,24 @@ static void highlightTarget(const TranslatableEntry &target, bool on) #ifndef QT_NO_COMBOBOX case TranslatableComboBoxItem: #endif + bringToFront(static_cast<QWidget *>(target.target.object)); highlightWidget(static_cast<QWidget *>(target.target.object), on); break; #ifndef QT_NO_LISTWIDGET case TranslatableListWidgetItem: + bringToFront(target.target.listWidgetItem->listWidget()); highlightWidgetItem(target.target.listWidgetItem, on); break; #endif #ifndef QT_NO_TABLEWIDGET case TranslatableTableWidgetItem: + bringToFront(target.target.tableWidgetItem->tableWidget()); highlightWidgetItem(target.target.tableWidgetItem, on); break; #endif #ifndef QT_NO_TREEWIDGET case TranslatableTreeWidgetItem: + bringToFront(target.target.treeWidgetItem->treeWidget()); highlightTreeWidgetItem(target.target.treeWidgetItem, target.prop.treeIndex.column, on); break; #endif |