forked from qt-creator/qt-creator
Utils::TreeWidgetColumStretcher: Generalize to support all QHeaderViews
I need this for a QTableView. Change-Id: I07f4c6561abc2c62ce19a21a2233c65210329ef6 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "treewidgetcolumnstretcher.h"
|
||||
#include "headerviewstretcher.h"
|
||||
#include <QTreeWidget>
|
||||
#include <QHideEvent>
|
||||
#include <QHeaderView>
|
||||
@@ -35,24 +35,24 @@
|
||||
using namespace Utils;
|
||||
|
||||
/*!
|
||||
\class Utils::TreeWidgetColumnStretcher
|
||||
\class Utils::HeaderViewStretcher
|
||||
|
||||
\brief The class fixes QTreeWidget to resize all columns to contents, except one
|
||||
\brief The class fixes QHeaderView to resize all columns to contents, except one
|
||||
stretching column.
|
||||
|
||||
As opposed to standard QTreeWidget, all columns are
|
||||
still interactively resizable.
|
||||
*/
|
||||
|
||||
TreeWidgetColumnStretcher::TreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch)
|
||||
: QObject(treeWidget->header()), m_columnToStretch(columnToStretch)
|
||||
HeaderViewStretcher::HeaderViewStretcher(QHeaderView *headerView, int columnToStretch)
|
||||
: QObject(headerView), m_columnToStretch(columnToStretch)
|
||||
{
|
||||
parent()->installEventFilter(this);
|
||||
headerView->installEventFilter(this);
|
||||
QHideEvent fake;
|
||||
TreeWidgetColumnStretcher::eventFilter(parent(), &fake);
|
||||
HeaderViewStretcher::eventFilter(headerView, &fake);
|
||||
}
|
||||
|
||||
bool TreeWidgetColumnStretcher::eventFilter(QObject *obj, QEvent *ev)
|
||||
bool HeaderViewStretcher::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
if (obj == parent()) {
|
||||
if (ev->type() == QEvent::Show) {
|
||||
@@ -27,27 +27,27 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef TREEWIDGETCOLUMNSTRETCHER_H
|
||||
#define TREEWIDGETCOLUMNSTRETCHER_H
|
||||
#ifndef HEADERVIEWSTRETCHER_H
|
||||
#define HEADERVIEWSTRETCHER_H
|
||||
|
||||
#include "utils_global.h"
|
||||
#include <QObject>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTreeWidget;
|
||||
class QHeaderView;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT TreeWidgetColumnStretcher : public QObject
|
||||
class QTCREATOR_UTILS_EXPORT HeaderViewStretcher : public QObject
|
||||
{
|
||||
const int m_columnToStretch;
|
||||
public:
|
||||
explicit TreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch);
|
||||
explicit HeaderViewStretcher(QHeaderView *headerView, int columnToStretch);
|
||||
|
||||
virtual bool eventFilter(QObject *obj, QEvent *ev);
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
#endif // TREEWIDGETCOLUMNSTRETCHER_H
|
||||
#endif // HEADERVIEWSTRETCHER_H
|
||||
@@ -45,7 +45,7 @@ SOURCES += $$PWD/environment.cpp \
|
||||
$$PWD/consoleprocess.cpp \
|
||||
$$PWD/uncommentselection.cpp \
|
||||
$$PWD/parameteraction.cpp \
|
||||
$$PWD/treewidgetcolumnstretcher.cpp \
|
||||
$$PWD/headerviewstretcher.cpp \
|
||||
$$PWD/checkablemessagebox.cpp \
|
||||
$$PWD/styledbar.cpp \
|
||||
$$PWD/stylehelper.cpp \
|
||||
@@ -129,7 +129,7 @@ HEADERS += \
|
||||
$$PWD/textfileformat.h \
|
||||
$$PWD/uncommentselection.h \
|
||||
$$PWD/parameteraction.h \
|
||||
$$PWD/treewidgetcolumnstretcher.h \
|
||||
$$PWD/headerviewstretcher.h \
|
||||
$$PWD/checkablemessagebox.h \
|
||||
$$PWD/qtcassert.h \
|
||||
$$PWD/styledbar.h \
|
||||
|
||||
@@ -161,8 +161,8 @@ QtcLibrary {
|
||||
"tcpportsgatherer.h",
|
||||
"textfileformat.cpp",
|
||||
"textfileformat.h",
|
||||
"treewidgetcolumnstretcher.cpp",
|
||||
"treewidgetcolumnstretcher.h",
|
||||
"headerviewstretcher.cpp",
|
||||
"headerviewstretcher.h",
|
||||
"uncommentselection.cpp",
|
||||
"uncommentselection.h",
|
||||
"unixutils.cpp",
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "id.h"
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/treewidgetcolumnstretcher.h>
|
||||
#include <utils/headerviewstretcher.h>
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QShortcut>
|
||||
@@ -90,7 +90,7 @@ QWidget *CommandMappings::createPage(QWidget *parent)
|
||||
connect(m_page->targetEdit, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(targetIdentifierChanged()));
|
||||
|
||||
new Utils::TreeWidgetColumnStretcher(m_page->commandList, 1);
|
||||
new Utils::HeaderViewStretcher(m_page->commandList->header(), 1);
|
||||
|
||||
commandChanged(0);
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/savedaction.h>
|
||||
#include <utils/treewidgetcolumnstretcher.h>
|
||||
#include <utils/stylehelper.h>
|
||||
|
||||
#include <cpptools/cpptoolsconstants.h>
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <utils/treewidgetcolumnstretcher.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/buildablehelperlibrary.h>
|
||||
#include <utils/pathchooser.h>
|
||||
|
||||
Reference in New Issue
Block a user