Commit c1b6571d authored by Eike Ziller's avatar Eike Ziller

Allow resizing of locator edit

Task-number: QTCREATORBUG-6719

Change-Id: I97a8972da3cb793324ca366bf4c977553e6bb38d
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent e75cd440
......@@ -235,7 +235,7 @@ LocatorWidget::LocatorWidget(Locator *qop) :
setFocusProxy(m_fileLineEdit);
setWindowTitle(tr("Locate..."));
resize(200, 90);
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
setSizePolicy(sizePolicy);
......
......@@ -1263,6 +1263,7 @@ void MainWindow::restoreWindowState()
restoreState(settings->value(QLatin1String(windowStateKey)).toByteArray());
settings->endGroup();
show();
m_statusBarManager->restoreSettings();
}
} // namespace Internal
......
......@@ -41,8 +41,9 @@ namespace Internal {
class MiniSplitterHandle : public QSplitterHandle
{
public:
MiniSplitterHandle(Qt::Orientation orientation, QSplitter *parent)
: QSplitterHandle(orientation, parent)
MiniSplitterHandle(Qt::Orientation orientation, QSplitter *parent, bool lightColored = false)
: QSplitterHandle(orientation, parent),
m_lightColored(lightColored)
{
setMask(QRegion(contentsRect()));
setAttribute(Qt::WA_MouseNoMask, true);
......@@ -50,6 +51,9 @@ public:
protected:
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent *event);
private:
bool m_lightColored;
};
} // namespace Internal
......@@ -71,24 +75,26 @@ void MiniSplitterHandle::resizeEvent(QResizeEvent *event)
void MiniSplitterHandle::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.fillRect(event->rect(), Utils::StyleHelper::borderColor());
painter.fillRect(event->rect(), Utils::StyleHelper::borderColor(m_lightColored));
}
QSplitterHandle *MiniSplitter::createHandle()
{
return new MiniSplitterHandle(orientation(), this);
return new MiniSplitterHandle(orientation(), this, m_style == Light);
}
MiniSplitter::MiniSplitter(QWidget *parent)
: QSplitter(parent)
MiniSplitter::MiniSplitter(QWidget *parent, SplitterStyle style)
: QSplitter(parent),
m_style(style)
{
setHandleWidth(1);
setChildrenCollapsible(false);
setProperty("minisplitter", true);
}
MiniSplitter::MiniSplitter(Qt::Orientation orientation)
: QSplitter(orientation)
MiniSplitter::MiniSplitter(Qt::Orientation orientation, SplitterStyle style)
: QSplitter(orientation),
m_style(style)
{
setHandleWidth(1);
setChildrenCollapsible(false);
......
......@@ -44,11 +44,16 @@ namespace Core {
class CORE_EXPORT MiniSplitter : public QSplitter
{
public:
MiniSplitter(QWidget *parent = 0);
MiniSplitter(Qt::Orientation orientation);
enum SplitterStyle {Dark, Light};
MiniSplitter(QWidget *parent = 0, SplitterStyle style = Dark);
MiniSplitter(Qt::Orientation orientation, SplitterStyle style = Dark);
protected:
QSplitterHandle *createHandle();
private:
SplitterStyle m_style;
};
} // namespace Core
......
......@@ -36,8 +36,13 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QResizeEvent>
#include <QSplitter>
#include <QStatusBar>
static const char kSettingsGroup[] = "StatusBar";
static const char kLeftSplitWidthKey[] = "LeftSplitWidth";
using namespace Core;
using namespace Core::Internal;
......@@ -55,16 +60,31 @@ StatusBarManager::StatusBarManager(MainWindow *mainWnd)
m_mainWnd(mainWnd)
{
QStatusBar *bar = m_mainWnd->statusBar();
for (int i = 0; i <= StatusBarWidget::LastLeftAligned; ++i) {
QWidget *w = createWidget(bar);
bar->insertPermanentWidget(i, w);
m_statusBarWidgets.append(w);
}
m_mainWnd->statusBar()->insertPermanentWidget(StatusBarWidget::LastLeftAligned + 1,
new QLabel(), 1);
m_splitter = new NonResizingSplitter(bar);
bar->insertPermanentWidget(0, m_splitter, 10);
m_splitter->setChildrenCollapsible(false);
// first
QWidget *w = createWidget(m_splitter);
w->layout()->setContentsMargins(0, 0, 3, 0);
m_splitter->addWidget(w);
m_statusBarWidgets.append(w);
QWidget *w2 = createWidget(m_splitter);
w2->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
m_splitter->addWidget(w2);
// second
w = createWidget(w2);
w2->layout()->addWidget(w);
m_statusBarWidgets.append(w);
// third
w = createWidget(w2);
w2->layout()->addWidget(w);
m_statusBarWidgets.append(w);
static_cast<QBoxLayout *>(w2->layout())->addStretch(1);
QWidget *rightCornerWidget = createWidget(bar);
m_mainWnd->statusBar()->insertPermanentWidget(StatusBarWidget::LastLeftAligned + 2,
rightCornerWidget);
bar->insertPermanentWidget(1, rightCornerWidget);
m_statusBarWidgets.append(rightCornerWidget);
}
......@@ -78,6 +98,7 @@ void StatusBarManager::init()
this, SLOT(objectAdded(QObject*)));
connect(ExtensionSystem::PluginManager::instance(), SIGNAL(aboutToRemoveObject(QObject*)),
this, SLOT(aboutToRemoveObject(QObject*)));
connect(ICore::instance(), SIGNAL(saveSettingsRequested()), this, SLOT(saveSettings()));
}
void StatusBarManager::objectAdded(QObject *obj)
......@@ -101,6 +122,44 @@ void StatusBarManager::aboutToRemoveObject(QObject *obj)
m_mainWnd->removeContextObject(view);
}
void StatusBarManager::saveSettings()
{
QSettings *s = ICore::settings();
s->beginGroup(QLatin1String(kSettingsGroup));
s->setValue(QLatin1String(kLeftSplitWidthKey), m_splitter->sizes().at(0));
s->endGroup();
}
void StatusBarManager::extensionsInitalized()
{
}
void StatusBarManager::restoreSettings()
{
QSettings *s = ICore::settings();
s->beginGroup(QLatin1String(kSettingsGroup));
int leftSplitWidth = s->value(QLatin1String(kLeftSplitWidthKey), -1).toInt();
s->endGroup();
if (leftSplitWidth < 0) {
// size first split after its sizeHint + a bit of buffer
leftSplitWidth = m_splitter->widget(0)->sizeHint().width();
}
int sum = 0;
foreach (int w, m_splitter->sizes())
sum += w;
m_splitter->setSizes(QList<int>() << leftSplitWidth << (sum - leftSplitWidth));
}
NonResizingSplitter::NonResizingSplitter(QWidget *parent)
: MiniSplitter(parent, Light)
{
}
void NonResizingSplitter::resizeEvent(QResizeEvent *ev)
{
// bypass QSplitter magic
int leftSplitWidth = qMin(sizes().at(0), ev->size().width());
int rightSplitWidth = qMax(0, ev->size().width() - leftSplitWidth);
setSizes(QList<int>() << leftSplitWidth << rightSplitWidth);
return QWidget::resizeEvent(ev);
}
......@@ -30,16 +30,31 @@
#ifndef STATUSBARMANAGER_H
#define STATUSBARMANAGER_H
#include <QObject>
#include "minisplitter.h"
#include <QList>
#include <QObject>
QT_FORWARD_DECLARE_CLASS(QWidget)
QT_BEGIN_NAMESPACE
class QWidget;
QT_END_NAMESPACE
namespace Core {
namespace Internal {
class MainWindow;
class NonResizingSplitter : public MiniSplitter
{
Q_OBJECT
public:
explicit NonResizingSplitter(QWidget *parent);
protected:
void resizeEvent(QResizeEvent *ev);
};
class StatusBarManager : public QObject
{
Q_OBJECT
......@@ -50,13 +65,16 @@ public:
void init();
void extensionsInitalized();
void restoreSettings();
private slots:
void objectAdded(QObject *obj);
void aboutToRemoveObject(QObject *obj);
void saveSettings();
private:
MainWindow *m_mainWnd;
QSplitter *m_splitter;
QList<QWidget *> m_statusBarWidgets;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment