diff options
author | mae <qt-info@nokia.com> | 2009-06-04 14:43:16 +0200 |
---|---|---|
committer | mae <qt-info@nokia.com> | 2009-06-04 14:44:05 +0200 |
commit | fda09bbc62ae14f6174f4b4f2da4374b3f70dfae (patch) | |
tree | 6d8a0727ed406cbed2059d87d32e104a7d7356b3 | |
parent | 98e695e31ba6b46d57e7269c184f29965f9367f7 (diff) | |
download | qt-creator-fda09bbc62ae14f6174f4b4f2da4374b3f70dfae.tar.gz |
introduce new helper class Core::Utils::TreeWidgetColumnStretcher
and use it for some options dialogs.
The class fixes QTreeWidget to resize all columns to contents, except one
stretching column. As opposed to standard QTreeWidget, all columns are
still interactively resizable.
-rw-r--r-- | src/libs/utils/treewidgetcolumnstretcher.cpp | 36 | ||||
-rw-r--r-- | src/libs/utils/treewidgetcolumnstretcher.h | 63 | ||||
-rw-r--r-- | src/libs/utils/utils.pro | 37 | ||||
-rw-r--r-- | src/plugins/coreplugin/dialogs/shortcutsettings.cpp | 7 | ||||
-rw-r--r-- | src/plugins/qt4projectmanager/qtoptionspage.cpp | 5 |
5 files changed, 122 insertions, 26 deletions
diff --git a/src/libs/utils/treewidgetcolumnstretcher.cpp b/src/libs/utils/treewidgetcolumnstretcher.cpp new file mode 100644 index 0000000000..d33c04ac4e --- /dev/null +++ b/src/libs/utils/treewidgetcolumnstretcher.cpp @@ -0,0 +1,36 @@ +#include "treewidgetcolumnstretcher.h" +#include <QtGui/QTreeWidget> +#include <QtGui/QHideEvent> +#include <QtGui/QHeaderView> +using namespace Core::Utils; + +TreeWidgetColumnStretcher::TreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch) + : QObject(treeWidget->header()), m_columnToStretch(columnToStretch) +{ + parent()->installEventFilter(this); + QHideEvent fake; + TreeWidgetColumnStretcher::eventFilter(parent(), &fake); +} + +bool TreeWidgetColumnStretcher::eventFilter(QObject *obj, QEvent *ev) +{ + if (obj == parent()) { + if (ev->type() == QEvent::Show) { + QHeaderView *hv = qobject_cast<QHeaderView*>(obj); + for (int i = 0; i < hv->count(); ++i) + hv->setResizeMode(i, QHeaderView::Interactive); + } else if (ev->type() == QEvent::Hide) { + QHeaderView *hv = qobject_cast<QHeaderView*>(obj); + for (int i = 0; i < hv->count(); ++i) + hv->setResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents); + } else if (ev->type() == QEvent::Resize) { + QHeaderView *hv = qobject_cast<QHeaderView*>(obj); + if (hv->resizeMode(m_columnToStretch) == QHeaderView::Interactive) { + QResizeEvent *re = static_cast<QResizeEvent*>(ev); + int diff = re->size().width() - re->oldSize().width() ; + hv->resizeSection(m_columnToStretch, qMax(32, hv->sectionSize(1) + diff)); + } + } + } + return false; +} diff --git a/src/libs/utils/treewidgetcolumnstretcher.h b/src/libs/utils/treewidgetcolumnstretcher.h new file mode 100644 index 0000000000..890f460289 --- /dev/null +++ b/src/libs/utils/treewidgetcolumnstretcher.h @@ -0,0 +1,63 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +**************************************************************************/ + +#ifndef TREEWIDGETCOLUMNSTRETCHER_H +#define TREEWIDGETCOLUMNSTRETCHER_H + +#include "utils_global.h" +#include <QObject> + +QT_BEGIN_NAMESPACE +class QTreeWidget; +QT_END_NAMESPACE + +namespace Core { +namespace Utils { + +/* + +The class fixes QTreeWidget to resize all columns to contents, except one +stretching column. As opposed to standard QTreeWidget, all columns are +still interactively resizable. + +*/ + +class QTCREATOR_UTILS_EXPORT TreeWidgetColumnStretcher : public QObject +{ + int m_columnToStretch; +public: + TreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch); + + bool eventFilter(QObject *obj, QEvent *ev); +}; + +} // namespace Utils +} // namespace Core + +#endif // TREEWIDGETCOLUMNSTRETCHER_H diff --git a/src/libs/utils/utils.pro b/src/libs/utils/utils.pro index c1085aac37..a35874026b 100644 --- a/src/libs/utils/utils.pro +++ b/src/libs/utils/utils.pro @@ -1,13 +1,10 @@ TEMPLATE = lib TARGET = Utils -QT += gui network - +QT += gui \ + network DEFINES += QTCREATOR_UTILS_LIBRARY - include(../../qtcreatorlibrary.pri) - -SOURCES += \ - reloadpromptutils.cpp \ +SOURCES += reloadpromptutils.cpp \ settingsutils.cpp \ filesearch.cpp \ pathchooser.cpp \ @@ -30,19 +27,16 @@ SOURCES += \ submitfieldwidget.cpp \ consoleprocess.cpp \ uncommentselection.cpp \ - parameteraction.cpp - -win32 { + parameteraction.cpp \ + treewidgetcolumnstretcher.cpp +win32 { SOURCES += abstractprocess_win.cpp \ - consoleprocess_win.cpp \ - winutils.cpp + consoleprocess_win.cpp \ + winutils.cpp HEADERS += winutils.h -} else { - SOURCES += consoleprocess_unix.cpp } - -HEADERS += \ - utils_global.h \ +else:SOURCES += consoleprocess_unix.cpp +HEADERS += utils_global.h \ reloadpromptutils.h \ settingsutils.h \ filesearch.h \ @@ -68,11 +62,10 @@ HEADERS += \ synchronousprocess.h \ submitfieldwidget.h \ uncommentselection.h \ - parameteraction.h - + parameteraction.h \ + treewidgetcolumnstretcher.h FORMS += filewizardpage.ui \ - projectintropage.ui \ - newclasswidget.ui \ - submiteditorwidget.ui - + projectintropage.ui \ + newclasswidget.ui \ + submiteditorwidget.ui RESOURCES += utils.qrc diff --git a/src/plugins/coreplugin/dialogs/shortcutsettings.cpp b/src/plugins/coreplugin/dialogs/shortcutsettings.cpp index 561b8b182d..a8666becd7 100644 --- a/src/plugins/coreplugin/dialogs/shortcutsettings.cpp +++ b/src/plugins/coreplugin/dialogs/shortcutsettings.cpp @@ -37,6 +37,8 @@ #include "filemanager.h" #include "icore.h" #include "uniqueidmanager.h" +#include <utils/treewidgetcolumnstretcher.h> + #include <QtGui/QKeyEvent> #include <QtGui/QShortcut> @@ -111,10 +113,7 @@ QWidget *ShortcutSettings::createPage(QWidget *parent) this, SLOT(commandChanged(QTreeWidgetItem *))); connect(m_page->shortcutEdit, SIGNAL(textChanged(QString)), this, SLOT(keyChanged())); - QHeaderView *hv = m_page->commandList->header(); - hv->resizeSection(0, 210); - hv->resizeSection(1, 110); - hv->setStretchLastSection(true); + new Core::Utils::TreeWidgetColumnStretcher(m_page->commandList, 1); commandChanged(0); diff --git a/src/plugins/qt4projectmanager/qtoptionspage.cpp b/src/plugins/qt4projectmanager/qtoptionspage.cpp index e61904d1df..b85607e3ea 100644 --- a/src/plugins/qt4projectmanager/qtoptionspage.cpp +++ b/src/plugins/qt4projectmanager/qtoptionspage.cpp @@ -4,6 +4,7 @@ #include "qt4projectmanagerconstants.h" #include "qtversionmanager.h" #include <coreplugin/coreconstants.h> +#include <utils/treewidgetcolumnstretcher.h> #include <QtCore/QDebug> #include <QtCore/QDir> @@ -60,6 +61,8 @@ void QtOptionsPage::apply() } //----------------------------------------------------- + + QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent, QList<QtVersion *> versions, QtVersion *defaultVersion) : QWidget(parent) , m_defaultVersion(versions.indexOf(defaultVersion)) @@ -82,6 +85,8 @@ QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent, QList<QtVersion *> ver m_ui->addButton->setIcon(QIcon(Core::Constants::ICON_PLUS)); m_ui->delButton->setIcon(QIcon(Core::Constants::ICON_MINUS)); + new Core::Utils::TreeWidgetColumnStretcher(m_ui->qtdirList, 1); + for (int i = 0; i < m_versions.count(); ++i) { const QtVersion * const version = m_versions.at(i); QTreeWidgetItem *item = new QTreeWidgetItem(m_ui->qtdirList); |