1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

[OP-835] Qt 5.1.0 - uncrustified gcs sources

This commit is contained in:
Philippe Renon 2013-10-17 21:45:37 +02:00
parent 28e57242f7
commit 09408b40ca
16 changed files with 677 additions and 541 deletions

View File

@ -444,7 +444,6 @@ void loadTranslators(QString language, QTranslator &translator, QTranslator &qtT
} }
} }
} }
} // namespace anonymous } // namespace anonymous
int main(int argc, char * *argv) int main(int argc, char * *argv)
@ -457,7 +456,7 @@ int main(int argc, char * *argv)
systemInit(); systemInit();
#ifdef QT_NO_DEBUG #ifdef QT_NO_DEBUG
// logInit(); // logInit();
#endif #endif
// create application // create application

View File

@ -35,13 +35,12 @@
#include <QDockWidget> #include <QDockWidget>
#include <QSettings> #include <QSettings>
static const char lockedKeyC[] = "Locked"; static const char lockedKeyC[] = "Locked";
static const char stateKeyC[] = "State"; static const char stateKeyC[] = "State";
static const int settingsVersion = 2; static const int settingsVersion = 2;
static const char dockWidgetActiveState[] = "DockWidgetActiveState"; static const char dockWidgetActiveState[] = "DockWidgetActiveState";
namespace Utils { namespace Utils {
/*! \class Utils::FancyMainWindow /*! \class Utils::FancyMainWindow
\brief MainWindow with dock widgets and additional "lock" functionality \brief MainWindow with dock widgets and additional "lock" functionality
@ -49,14 +48,13 @@ namespace Utils {
The dock actions and the additional actions should be accessible The dock actions and the additional actions should be accessible
in a Window-menu. in a Window-menu.
*/ */
struct FancyMainWindowPrivate struct FancyMainWindowPrivate {
{
FancyMainWindowPrivate(); FancyMainWindowPrivate();
bool m_locked; bool m_locked;
bool m_handleDockVisibilityChanges; bool m_handleDockVisibilityChanges;
QAction m_menuSeparator1; QAction m_menuSeparator1;
QAction m_toggleLockedAction; QAction m_toggleLockedAction;
@ -97,15 +95,17 @@ FancyMainWindow::~FancyMainWindow()
QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget) QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget)
{ {
QDockWidget *dockWidget = new QDockWidget(widget->windowTitle(), this); QDockWidget *dockWidget = new QDockWidget(widget->windowTitle(), this);
dockWidget->setWidget(widget); dockWidget->setWidget(widget);
// Set an object name to be used in settings, derive from widget name // Set an object name to be used in settings, derive from widget name
const QString objectName = widget->objectName(); const QString objectName = widget->objectName();
if (objectName.isEmpty()) if (objectName.isEmpty()) {
dockWidget->setObjectName(QLatin1String("dockWidget") + QString::number(dockWidgets().size() + 1)); dockWidget->setObjectName(QLatin1String("dockWidget") + QString::number(dockWidgets().size() + 1));
else } else {
dockWidget->setObjectName(objectName + QLatin1String("DockWidget")); dockWidget->setObjectName(objectName + QLatin1String("DockWidget"));
}
connect(dockWidget->toggleViewAction(), SIGNAL(triggered()), connect(dockWidget->toggleViewAction(), SIGNAL(triggered()),
this, SLOT(onDockActionTriggered()), Qt::QueuedConnection); this, SLOT(onDockActionTriggered()), Qt::QueuedConnection);
connect(dockWidget, SIGNAL(visibilityChanged(bool)), connect(dockWidget, SIGNAL(visibilityChanged(bool)),
this, SLOT(onDockVisibilityChange(bool))); this, SLOT(onDockVisibilityChange(bool)));
connect(dockWidget, SIGNAL(topLevelChanged(bool)), connect(dockWidget, SIGNAL(topLevelChanged(bool)),
@ -118,13 +118,14 @@ QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget)
void FancyMainWindow::updateDockWidget(QDockWidget *dockWidget) void FancyMainWindow::updateDockWidget(QDockWidget *dockWidget)
{ {
const QDockWidget::DockWidgetFeatures features = const QDockWidget::DockWidgetFeatures features =
(d->m_locked) ? QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable (d->m_locked) ? QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable
: QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable; : QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable;
if (dockWidget->property("managed_dockwidget").isNull()) { // for the debugger tool bar if (dockWidget->property("managed_dockwidget").isNull()) { // for the debugger tool bar
QWidget *titleBarWidget = dockWidget->titleBarWidget(); QWidget *titleBarWidget = dockWidget->titleBarWidget();
if (d->m_locked && !titleBarWidget && !dockWidget->isFloating()) if (d->m_locked && !titleBarWidget && !dockWidget->isFloating()) {
titleBarWidget = new QWidget(dockWidget); titleBarWidget = new QWidget(dockWidget);
else if ((!d->m_locked || dockWidget->isFloating()) && titleBarWidget) { } else if ((!d->m_locked || dockWidget->isFloating()) && titleBarWidget) {
delete titleBarWidget; delete titleBarWidget;
titleBarWidget = 0; titleBarWidget = 0;
} }
@ -136,29 +137,32 @@ void FancyMainWindow::updateDockWidget(QDockWidget *dockWidget)
void FancyMainWindow::onDockActionTriggered() void FancyMainWindow::onDockActionTriggered()
{ {
QDockWidget *dw = qobject_cast<QDockWidget *>(sender()->parent()); QDockWidget *dw = qobject_cast<QDockWidget *>(sender()->parent());
if (dw) { if (dw) {
if (dw->isVisible()) if (dw->isVisible()) {
dw->raise(); dw->raise();
}
} }
} }
void FancyMainWindow::onDockVisibilityChange(bool visible) void FancyMainWindow::onDockVisibilityChange(bool visible)
{ {
if (d->m_handleDockVisibilityChanges) if (d->m_handleDockVisibilityChanges) {
sender()->setProperty(dockWidgetActiveState, visible); sender()->setProperty(dockWidgetActiveState, visible);
}
} }
void FancyMainWindow::onTopLevelChanged() void FancyMainWindow::onTopLevelChanged()
{ {
updateDockWidget(qobject_cast<QDockWidget*>(sender())); updateDockWidget(qobject_cast<QDockWidget *>(sender()));
} }
void FancyMainWindow::setTrackingEnabled(bool enabled) void FancyMainWindow::setTrackingEnabled(bool enabled)
{ {
if (enabled) { if (enabled) {
d->m_handleDockVisibilityChanges = true; d->m_handleDockVisibilityChanges = true;
foreach (QDockWidget *dockWidget, dockWidgets()) foreach(QDockWidget * dockWidget, dockWidgets())
dockWidget->setProperty(dockWidgetActiveState, dockWidget->isVisible()); dockWidget->setProperty(dockWidgetActiveState, dockWidget->isVisible());
} else { } else {
d->m_handleDockVisibilityChanges = false; d->m_handleDockVisibilityChanges = false;
} }
@ -167,7 +171,7 @@ void FancyMainWindow::setTrackingEnabled(bool enabled)
void FancyMainWindow::setLocked(bool locked) void FancyMainWindow::setLocked(bool locked)
{ {
d->m_locked = locked; d->m_locked = locked;
foreach (QDockWidget *dockWidget, dockWidgets()) { foreach(QDockWidget * dockWidget, dockWidgets()) {
updateDockWidget(dockWidget); updateDockWidget(dockWidget);
} }
} }
@ -187,6 +191,7 @@ void FancyMainWindow::showEvent(QShowEvent *event)
void FancyMainWindow::contextMenuEvent(QContextMenuEvent *event) void FancyMainWindow::contextMenuEvent(QContextMenuEvent *event)
{ {
QMenu *menu = createPopupMenu(); QMenu *menu = createPopupMenu();
menu->exec(event->globalPos()); menu->exec(event->globalPos());
delete menu; delete menu;
} }
@ -194,14 +199,15 @@ void FancyMainWindow::contextMenuEvent(QContextMenuEvent *event)
void FancyMainWindow::handleVisibilityChanged(bool visible) void FancyMainWindow::handleVisibilityChanged(bool visible)
{ {
d->m_handleDockVisibilityChanges = false; d->m_handleDockVisibilityChanges = false;
foreach (QDockWidget *dockWidget, dockWidgets()) { foreach(QDockWidget * dockWidget, dockWidgets()) {
if (dockWidget->isFloating()) { if (dockWidget->isFloating()) {
dockWidget->setVisible(visible dockWidget->setVisible(visible
&& dockWidget->property(dockWidgetActiveState).toBool()); && dockWidget->property(dockWidgetActiveState).toBool());
} }
} }
if (visible) if (visible) {
d->m_handleDockVisibilityChanges = true; d->m_handleDockVisibilityChanges = true;
}
} }
void FancyMainWindow::saveSettings(QSettings *settings) const void FancyMainWindow::saveSettings(QSettings *settings) const
@ -217,7 +223,7 @@ void FancyMainWindow::saveSettings(QSettings *settings) const
void FancyMainWindow::restoreSettings(const QSettings *settings) void FancyMainWindow::restoreSettings(const QSettings *settings)
{ {
QHash<QString, QVariant> hash; QHash<QString, QVariant> hash;
foreach (const QString &key, settings->childKeys()) { foreach(const QString &key, settings->childKeys()) {
hash.insert(key, settings->value(key)); hash.insert(key, settings->value(key));
} }
restoreSettings(hash); restoreSettings(hash);
@ -228,9 +234,9 @@ QHash<QString, QVariant> FancyMainWindow::saveSettings() const
QHash<QString, QVariant> settings; QHash<QString, QVariant> settings;
settings.insert(QLatin1String(stateKeyC), saveState(settingsVersion)); settings.insert(QLatin1String(stateKeyC), saveState(settingsVersion));
settings.insert(QLatin1String(lockedKeyC), d->m_locked); settings.insert(QLatin1String(lockedKeyC), d->m_locked);
foreach (QDockWidget *dockWidget, dockWidgets()) { foreach(QDockWidget * dockWidget, dockWidgets()) {
settings.insert(dockWidget->objectName(), settings.insert(dockWidget->objectName(),
dockWidget->property(dockWidgetActiveState)); dockWidget->property(dockWidgetActiveState));
} }
return settings; return settings;
} }
@ -238,13 +244,15 @@ QHash<QString, QVariant> FancyMainWindow::saveSettings() const
void FancyMainWindow::restoreSettings(const QHash<QString, QVariant> &settings) void FancyMainWindow::restoreSettings(const QHash<QString, QVariant> &settings)
{ {
QByteArray ba = settings.value(QLatin1String(stateKeyC), QByteArray()).toByteArray(); QByteArray ba = settings.value(QLatin1String(stateKeyC), QByteArray()).toByteArray();
if (!ba.isEmpty())
if (!ba.isEmpty()) {
restoreState(ba, settingsVersion); restoreState(ba, settingsVersion);
}
d->m_locked = settings.value(QLatin1String("Locked"), true).toBool(); d->m_locked = settings.value(QLatin1String("Locked"), true).toBool();
d->m_toggleLockedAction.setChecked(d->m_locked); d->m_toggleLockedAction.setChecked(d->m_locked);
foreach (QDockWidget *widget, dockWidgets()) { foreach(QDockWidget * widget, dockWidgets()) {
widget->setProperty(dockWidgetActiveState, widget->setProperty(dockWidgetActiveState,
settings.value(widget->objectName(), false)); settings.value(widget->objectName(), false));
} }
} }
@ -272,14 +280,14 @@ QMenu *FancyMainWindow::createPopupMenu()
for (int i = 0; i < dockwidgets.size(); ++i) { for (int i = 0; i < dockwidgets.size(); ++i) {
QDockWidget *dockWidget = dockwidgets.at(i); QDockWidget *dockWidget = dockwidgets.at(i);
if (dockWidget->property("managed_dockwidget").isNull() if (dockWidget->property("managed_dockwidget").isNull()
&& dockWidget->parentWidget() == this) { && dockWidget->parentWidget() == this) {
actions.append(dockwidgets.at(i)->toggleViewAction()); actions.append(dockwidgets.at(i)->toggleViewAction());
} }
} }
qSort(actions.begin(), actions.end(), actionLessThan); qSort(actions.begin(), actions.end(), actionLessThan);
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
foreach (QAction *action, actions) foreach(QAction * action, actions)
menu->addAction(action); menu->addAction(action);
menu->addAction(&d->m_menuSeparator1); menu->addAction(&d->m_menuSeparator1);
menu->addAction(&d->m_toggleLockedAction); menu->addAction(&d->m_toggleLockedAction);
menu->addAction(&d->m_menuSeparator2); menu->addAction(&d->m_menuSeparator2);
@ -309,8 +317,8 @@ QAction *FancyMainWindow::resetLayoutAction() const
void FancyMainWindow::setDockActionsVisible(bool v) void FancyMainWindow::setDockActionsVisible(bool v)
{ {
foreach (const QDockWidget *dockWidget, dockWidgets()) foreach(const QDockWidget * dockWidget, dockWidgets())
dockWidget->toggleViewAction()->setVisible(v); dockWidget->toggleViewAction()->setVisible(v);
d->m_toggleLockedAction.setVisible(v); d->m_toggleLockedAction.setVisible(v);
d->m_menuSeparator1.setVisible(v); d->m_menuSeparator1.setVisible(v);
d->m_menuSeparator2.setVisible(v); d->m_menuSeparator2.setVisible(v);
@ -326,5 +334,4 @@ void FancyMainWindow::setToolBarDockWidget(QDockWidget *dock)
{ {
d->m_toolBarDockWidget = dock; d->m_toolBarDockWidget = dock;
} }
} // namespace Utils } // namespace Utils

View File

@ -38,11 +38,9 @@ class QSettings;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Utils { namespace Utils {
struct FancyMainWindowPrivate; struct FancyMainWindowPrivate;
class QTCREATOR_UTILS_EXPORT FancyMainWindow : public QMainWindow class QTCREATOR_UTILS_EXPORT FancyMainWindow : public QMainWindow {
{
Q_OBJECT Q_OBJECT
public: public:
@ -99,7 +97,6 @@ private:
FancyMainWindowPrivate *d; FancyMainWindowPrivate *d;
}; };
} // namespace Utils } // namespace Utils
#endif // FANCYMAINWINDOW_H #endif // FANCYMAINWINDOW_H

View File

@ -42,17 +42,21 @@ HostOsInfo::HostArchitecture HostOsInfo::hostArchitecture()
switch (info.wProcessorArchitecture) { switch (info.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64: case PROCESSOR_ARCHITECTURE_AMD64:
return HostOsInfo::HostArchitectureAMD64; return HostOsInfo::HostArchitectureAMD64;
case PROCESSOR_ARCHITECTURE_INTEL: case PROCESSOR_ARCHITECTURE_INTEL:
return HostOsInfo::HostArchitectureX86; return HostOsInfo::HostArchitectureX86;
case PROCESSOR_ARCHITECTURE_IA64: case PROCESSOR_ARCHITECTURE_IA64:
return HostOsInfo::HostArchitectureItanium; return HostOsInfo::HostArchitectureItanium;
case PROCESSOR_ARCHITECTURE_ARM: case PROCESSOR_ARCHITECTURE_ARM:
return HostOsInfo::HostArchitectureArm; return HostOsInfo::HostArchitectureArm;
default: default:
return HostOsInfo::HostArchitectureUnknown; return HostOsInfo::HostArchitectureUnknown;
} }
#else #else
return HostOsInfo::HostArchitectureUnknown; return HostOsInfo::HostArchitectureUnknown;
#endif
}
#endif // ifdef Q_OS_WIN
}

View File

@ -40,9 +40,7 @@
#endif // Q_OS_WIN #endif // Q_OS_WIN
namespace Utils { namespace Utils {
class QTCREATOR_UTILS_EXPORT HostOsInfo {
class QTCREATOR_UTILS_EXPORT HostOsInfo
{
public: public:
// Add more as needed. // Add more as needed.
enum HostOs { HostOsWindows, HostOsLinux, HostOsMac, HostOsOtherUnix, HostOsOther }; enum HostOs { HostOsWindows, HostOsLinux, HostOsMac, HostOsOtherUnix, HostOsOther };
@ -52,22 +50,33 @@ public:
HostArchitectureArm, HostArchitectureUnknown }; HostArchitectureArm, HostArchitectureUnknown };
static HostArchitecture hostArchitecture(); static HostArchitecture hostArchitecture();
static bool isWindowsHost() { return hostOs() == HostOsWindows; } static bool isWindowsHost()
static bool isLinuxHost() { return hostOs() == HostOsLinux; } {
static bool isMacHost() { return hostOs() == HostOsMac; } return hostOs() == HostOsWindows;
}
static bool isLinuxHost()
{
return hostOs() == HostOsLinux;
}
static bool isMacHost()
{
return hostOs() == HostOsMac;
}
static inline bool isAnyUnixHost(); static inline bool isAnyUnixHost();
static QString withExecutableSuffix(const QString &executable) static QString withExecutableSuffix(const QString &executable)
{ {
QString finalName = executable; QString finalName = executable;
if (isWindowsHost())
if (isWindowsHost()) {
finalName += QLatin1String(QTC_HOST_EXE_SUFFIX); finalName += QLatin1String(QTC_HOST_EXE_SUFFIX);
}
return finalName; return finalName;
} }
static Qt::CaseSensitivity fileNameCaseSensitivity() static Qt::CaseSensitivity fileNameCaseSensitivity()
{ {
return isWindowsHost() ? Qt::CaseInsensitive: Qt::CaseSensitive; return isWindowsHost() ? Qt::CaseInsensitive : Qt::CaseSensitive;
} }
static QChar pathListSeparator() static QChar pathListSeparator()
@ -85,14 +94,19 @@ HostOsInfo::HostOs HostOsInfo::hostOs()
{ {
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
return HostOsWindows; return HostOsWindows;
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
return HostOsLinux; return HostOsLinux;
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
return HostOsMac; return HostOsMac;
#elif defined(Q_OS_UNIX) #elif defined(Q_OS_UNIX)
return HostOsOtherUnix; return HostOsOtherUnix;
#else #else
return HostOsOther; return HostOsOther;
#endif #endif
} }
@ -100,11 +114,12 @@ bool HostOsInfo::isAnyUnixHost()
{ {
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
return true; return true;
#else #else
return false; return false;
#endif #endif
} }
} // namespace Utils } // namespace Utils
#endif // HOSTOSINFO_H #endif // HOSTOSINFO_H

View File

@ -66,7 +66,7 @@ void StyledBar::paintEvent(QPaintEvent *event)
Q_UNUSED(event) Q_UNUSED(event)
QPainter painter(this); QPainter painter(this);
QStyleOption option; QStyleOption option;
option.rect = rect(); option.rect = rect();
option.state = QStyle::State_Horizontal; option.state = QStyle::State_Horizontal;
style()->drawControl(QStyle::CE_ToolBar, &option, &painter, this); style()->drawControl(QStyle::CE_ToolBar, &option, &painter, this);
} }
@ -82,8 +82,8 @@ void StyledSeparator::paintEvent(QPaintEvent *event)
Q_UNUSED(event) Q_UNUSED(event)
QPainter painter(this); QPainter painter(this);
QStyleOption option; QStyleOption option;
option.rect = rect(); option.rect = rect();
option.state = QStyle::State_Horizontal; option.state = QStyle::State_Horizontal;
option.palette = palette(); option.palette = palette();
style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &option, &painter, this); style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &option, &painter, this);
} }

View File

@ -34,9 +34,7 @@
#include <QWidget> #include <QWidget>
namespace Utils { namespace Utils {
class QTCREATOR_UTILS_EXPORT StyledBar : public QWidget {
class QTCREATOR_UTILS_EXPORT StyledBar : public QWidget
{
Q_OBJECT Q_OBJECT
public: public:
StyledBar(QWidget *parent = 0); StyledBar(QWidget *parent = 0);
@ -50,15 +48,13 @@ protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
}; };
class QTCREATOR_UTILS_EXPORT StyledSeparator : public QWidget class QTCREATOR_UTILS_EXPORT StyledSeparator : public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
StyledSeparator(QWidget *parent = 0); StyledSeparator(QWidget *parent = 0);
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
}; };
} // Utils } // Utils
#endif // STYLEDBAR_H #endif // STYLEDBAR_H

View File

@ -40,24 +40,25 @@
static int clamp(float x) static int clamp(float x)
{ {
const int val = x > 255 ? 255 : static_cast<int>(x); const int val = x > 255 ? 255 : static_cast<int>(x);
return val < 0 ? 0 : val; return val < 0 ? 0 : val;
} }
// Clamps float color values within (0, 255) // Clamps float color values within (0, 255)
/* /*
static int range(float x, int min, int max) static int range(float x, int min, int max)
{ {
int val = x > max ? max : x; int val = x > max ? max : x;
return val < min ? min : val; return val < min ? min : val;
} }
*/ */
namespace Utils { namespace Utils {
QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int factor) QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int factor)
{ {
const int maxFactor = 100; const int maxFactor = 100;
QColor tmp = colorA; QColor tmp = colorA;
tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor); tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor); tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor); tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
@ -72,6 +73,7 @@ qreal StyleHelper::sidebarFontSize()
QPalette StyleHelper::sidebarFontPalette(const QPalette &original) QPalette StyleHelper::sidebarFontPalette(const QPalette &original)
{ {
QPalette palette = original; QPalette palette = original;
palette.setColor(QPalette::Active, QPalette::Text, panelTextColor()); palette.setColor(QPalette::Active, QPalette::Text, panelTextColor());
palette.setColor(QPalette::Active, QPalette::WindowText, panelTextColor()); palette.setColor(QPalette::Active, QPalette::WindowText, panelTextColor());
palette.setColor(QPalette::Inactive, QPalette::Text, panelTextColor().darker()); palette.setColor(QPalette::Inactive, QPalette::Text, panelTextColor().darker());
@ -81,11 +83,12 @@ QPalette StyleHelper::sidebarFontPalette(const QPalette &original)
QColor StyleHelper::panelTextColor(bool lightColored) QColor StyleHelper::panelTextColor(bool lightColored)
{ {
//qApp->palette().highlightedText().color(); // qApp->palette().highlightedText().color();
if (!lightColored) if (!lightColored) {
return Qt::white; return Qt::white;
else } else {
return Qt::black; return Qt::black;
}
} }
// Invalid by default, setBaseColor needs to be called at least once // Invalid by default, setBaseColor needs to be called at least once
@ -94,29 +97,33 @@ QColor StyleHelper::m_requestedBaseColor;
QColor StyleHelper::baseColor(bool lightColored) QColor StyleHelper::baseColor(bool lightColored)
{ {
if (!lightColored) if (!lightColored) {
return m_baseColor; return m_baseColor;
else } else {
return m_baseColor.lighter(230); return m_baseColor.lighter(230);
}
} }
QColor StyleHelper::highlightColor(bool lightColored) QColor StyleHelper::highlightColor(bool lightColored)
{ {
QColor result = baseColor(lightColored); QColor result = baseColor(lightColored);
if (!lightColored)
if (!lightColored) {
result.setHsv(result.hue(), result.setHsv(result.hue(),
clamp(result.saturation()), clamp(result.saturation()),
clamp(result.value() * 1.16)); clamp(result.value() * 1.16));
else } else {
result.setHsv(result.hue(), result.setHsv(result.hue(),
clamp(result.saturation()), clamp(result.saturation()),
clamp(result.value() * 1.06)); clamp(result.value() * 1.06));
}
return result; return result;
} }
QColor StyleHelper::shadowColor(bool lightColored) QColor StyleHelper::shadowColor(bool lightColored)
{ {
QColor result = baseColor(lightColored); QColor result = baseColor(lightColored);
result.setHsv(result.hue(), result.setHsv(result.hue(),
clamp(result.saturation() * 1.1), clamp(result.saturation() * 1.1),
clamp(result.value() * 0.70)); clamp(result.value() * 0.70));
@ -126,6 +133,7 @@ QColor StyleHelper::shadowColor(bool lightColored)
QColor StyleHelper::borderColor(bool lightColored) QColor StyleHelper::borderColor(bool lightColored)
{ {
QColor result = baseColor(lightColored); QColor result = baseColor(lightColored);
result.setHsv(result.hue(), result.setHsv(result.hue(),
result.saturation(), result.saturation(),
result.value() / 2); result.value() / 2);
@ -146,16 +154,17 @@ void StyleHelper::setBaseColor(const QColor &newcolor)
if (color.isValid() && color != m_baseColor) { if (color.isValid() && color != m_baseColor) {
m_baseColor = color; m_baseColor = color;
foreach (QWidget *w, QApplication::topLevelWidgets()) foreach(QWidget * w, QApplication::topLevelWidgets())
w->update(); w->update();
} }
} }
static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect, bool lightColored) static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect, bool lightColored)
{ {
QColor highlight = StyleHelper::highlightColor(lightColored); QColor highlight = StyleHelper::highlightColor(lightColored);
QColor shadow = StyleHelper::shadowColor(lightColored); QColor shadow = StyleHelper::shadowColor(lightColored);
QLinearGradient grad(spanRect.topRight(), spanRect.topLeft()); QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
grad.setColorAt(0, highlight.lighter(117)); grad.setColorAt(0, highlight.lighter(117));
grad.setColorAt(1, shadow.darker(109)); grad.setColorAt(1, shadow.darker(109));
p->fillRect(rect, grad); p->fillRect(rect, grad);
@ -174,8 +183,8 @@ void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, con
QString key; QString key;
QColor keyColor = baseColor(lightColored); QColor keyColor = baseColor(lightColored);
key.sprintf("mh_vertical %d %d %d %d %d", key.sprintf("mh_vertical %d %d %d %d %d",
spanRect.width(), spanRect.height(), clipRect.width(), spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), keyColor.rgb());; clipRect.height(), keyColor.rgb());;
QPixmap pixmap; QPixmap pixmap;
if (!QPixmapCache::find(key, pixmap)) { if (!QPixmapCache::find(key, pixmap)) {
@ -194,7 +203,7 @@ void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, con
} }
static void horizontalGradientHelper(QPainter *p, const QRect &spanRect, const static void horizontalGradientHelper(QPainter *p, const QRect &spanRect, const
QRect &rect, bool lightColored) QRect &rect, bool lightColored)
{ {
if (lightColored) { if (lightColored) {
QLinearGradient shadowGradient(rect.topLeft(), rect.bottomLeft()); QLinearGradient shadowGradient(rect.topLeft(), rect.bottomLeft());
@ -204,9 +213,9 @@ QRect &rect, bool lightColored)
return; return;
} }
QColor base = StyleHelper::baseColor(lightColored); QColor base = StyleHelper::baseColor(lightColored);
QColor highlight = StyleHelper::highlightColor(lightColored); QColor highlight = StyleHelper::highlightColor(lightColored);
QColor shadow = StyleHelper::shadowColor(lightColored); QColor shadow = StyleHelper::shadowColor(lightColored);
QLinearGradient grad(rect.topLeft(), rect.bottomLeft()); QLinearGradient grad(rect.topLeft(), rect.bottomLeft());
grad.setColorAt(0, highlight.lighter(120)); grad.setColorAt(0, highlight.lighter(120));
if (rect.height() == StyleHelper::navigationWidgetHeight()) { if (rect.height() == StyleHelper::navigationWidgetHeight()) {
@ -217,12 +226,12 @@ QRect &rect, bool lightColored)
p->fillRect(rect, grad); p->fillRect(rect, grad);
QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight()); QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight());
shadowGradient.setColorAt(0, QColor(0, 0, 0, 30)); shadowGradient.setColorAt(0, QColor(0, 0, 0, 30));
QColor lighterHighlight; QColor lighterHighlight;
lighterHighlight = highlight.lighter(130); lighterHighlight = highlight.lighter(130);
lighterHighlight.setAlpha(100); lighterHighlight.setAlpha(100);
shadowGradient.setColorAt(0.7, lighterHighlight); shadowGradient.setColorAt(0.7, lighterHighlight);
shadowGradient.setColorAt(1, QColor(0, 0, 0, 40)); shadowGradient.setColorAt(1, QColor(0, 0, 0, 40));
p->fillRect(rect, shadowGradient); p->fillRect(rect, shadowGradient);
} }
@ -232,8 +241,8 @@ void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, c
QString key; QString key;
QColor keyColor = baseColor(lightColored); QColor keyColor = baseColor(lightColored);
key.sprintf("mh_horizontal %d %d %d %d %d %d", key.sprintf("mh_horizontal %d %d %d %d %d %d",
spanRect.width(), spanRect.height(), clipRect.width(), spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), keyColor.rgb(), spanRect.x()); clipRect.height(), keyColor.rgb(), spanRect.x());
QPixmap pixmap; QPixmap pixmap;
if (!QPixmapCache::find(key, pixmap)) { if (!QPixmapCache::find(key, pixmap)) {
@ -246,7 +255,6 @@ void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, c
} }
painter->drawPixmap(clipRect.topLeft(), pixmap); painter->drawPixmap(clipRect.topLeft(), pixmap);
} else { } else {
horizontalGradientHelper(painter, spanRect, clipRect, lightColored); horizontalGradientHelper(painter, spanRect, clipRect, lightColored);
} }
@ -256,6 +264,7 @@ static void menuGradientHelper(QPainter *p, const QRect &spanRect, const QRect &
{ {
QLinearGradient grad(spanRect.topLeft(), spanRect.bottomLeft()); QLinearGradient grad(spanRect.topLeft(), spanRect.bottomLeft());
QColor menuColor = StyleHelper::mergedColors(StyleHelper::baseColor(), QColor(244, 244, 244), 25); QColor menuColor = StyleHelper::mergedColors(StyleHelper::baseColor(), QColor(244, 244, 244), 25);
grad.setColorAt(0, menuColor.lighter(112)); grad.setColorAt(0, menuColor.lighter(112));
grad.setColorAt(1, menuColor); grad.setColorAt(1, menuColor);
p->fillRect(rect, grad); p->fillRect(rect, grad);
@ -264,10 +273,11 @@ static void menuGradientHelper(QPainter *p, const QRect &spanRect, const QRect &
void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option) void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option)
{ {
// From windowsstyle but modified to enable AA // From windowsstyle but modified to enable AA
if (option->rect.width() <= 1 || option->rect.height() <= 1) if (option->rect.width() <= 1 || option->rect.height() <= 1) {
return; return;
}
QRect r = option->rect; QRect r = option->rect;
int size = qMin(r.height(), r.width()); int size = qMin(r.height(), r.width());
QPixmap pixmap; QPixmap pixmap;
QString pixmapName; QString pixmapName;
@ -276,8 +286,8 @@ void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter,
uint(option->state), element, uint(option->state), element,
size, option->palette.cacheKey()); size, option->palette.cacheKey());
if (!QPixmapCache::find(pixmapName, pixmap)) { if (!QPixmapCache::find(pixmapName, pixmap)) {
int border = size/5; int border = size / 5;
int sqsize = 2*(size/2); int sqsize = 2 * (size / 2);
QImage image(sqsize, sqsize, QImage::Format_ARGB32); QImage image(sqsize, sqsize, QImage::Format_ARGB32);
image.fill(Qt::transparent); image.fill(Qt::transparent);
QPainter imagePainter(&image); QPainter imagePainter(&image);
@ -285,20 +295,20 @@ void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter,
imagePainter.translate(0.5, 0.5); imagePainter.translate(0.5, 0.5);
QPolygon a; QPolygon a;
switch (element) { switch (element) {
case QStyle::PE_IndicatorArrowUp: case QStyle::PE_IndicatorArrowUp:
a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); a.setPoints(3, border, sqsize / 2, sqsize / 2, border, sqsize - border, sqsize / 2);
break; break;
case QStyle::PE_IndicatorArrowDown: case QStyle::PE_IndicatorArrowDown:
a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); a.setPoints(3, border, sqsize / 2, sqsize / 2, sqsize - border, sqsize - border, sqsize / 2);
break; break;
case QStyle::PE_IndicatorArrowRight: case QStyle::PE_IndicatorArrowRight:
a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); a.setPoints(3, sqsize - border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border);
break; break;
case QStyle::PE_IndicatorArrowLeft: case QStyle::PE_IndicatorArrowLeft:
a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); a.setPoints(3, border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border);
break; break;
default: default:
break; break;
} }
int bsx = 0; int bsx = 0;
@ -334,8 +344,8 @@ void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter,
pixmap = QPixmap::fromImage(image); pixmap = QPixmap::fromImage(image);
QPixmapCache::insert(pixmapName, pixmap); QPixmapCache::insert(pixmapName, pixmap);
} }
int xOffset = r.x() + (r.width() - size)/2; int xOffset = r.x() + (r.width() - size) / 2;
int yOffset = r.y() + (r.height() - size)/2; int yOffset = r.y() + (r.height() - size) / 2;
painter->drawPixmap(xOffset, yOffset, pixmap); painter->drawPixmap(xOffset, yOffset, pixmap);
} }
@ -344,8 +354,8 @@ void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const Q
if (StyleHelper::usePixmapCache()) { if (StyleHelper::usePixmapCache()) {
QString key; QString key;
key.sprintf("mh_menu %d %d %d %d %d", key.sprintf("mh_menu %d %d %d %d %d",
spanRect.width(), spanRect.height(), clipRect.width(), spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), StyleHelper::baseColor().rgb()); clipRect.height(), StyleHelper::baseColor().rgb());
QPixmap pixmap; QPixmap pixmap;
if (!QPixmapCache::find(key, pixmap)) { if (!QPixmapCache::find(key, pixmap)) {
@ -367,9 +377,11 @@ static qreal pixmapDevicePixelRatio(const QPixmap &pixmap)
{ {
#if QT_VERSION > 0x050000 #if QT_VERSION > 0x050000
return pixmap.devicePixelRatio(); return pixmap.devicePixelRatio();
#else #else
Q_UNUSED(pixmap); Q_UNUSED(pixmap);
return 1.0; return 1.0;
#endif #endif
} }
@ -386,9 +398,9 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
// return a high-dpi pixmap, which will in that case have a devicePixelRatio // return a high-dpi pixmap, which will in that case have a devicePixelRatio
// different than 1. The shadow drawing caluculations are done in device // different than 1. The shadow drawing caluculations are done in device
// pixels. // pixels.
QPixmap px = icon.pixmap(rect.size()); QPixmap px = icon.pixmap(rect.size());
int devicePixelRatio = qCeil(pixmapDevicePixelRatio(px)); int devicePixelRatio = qCeil(pixmapDevicePixelRatio(px));
int radius = dipRadius * devicePixelRatio; int radius = dipRadius * devicePixelRatio;
QPoint offset = dipOffset * devicePixelRatio; QPoint offset = dipOffset * devicePixelRatio;
cache = QPixmap(px.size() + QSize(radius * 2, radius * 2)); cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
@ -396,10 +408,10 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
QPainter cachePainter(&cache); QPainter cachePainter(&cache);
if (iconMode == QIcon::Disabled) { if (iconMode == QIcon::Disabled) {
QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32); QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
for (int y=0; y<im.height(); ++y) { for (int y = 0; y < im.height(); ++y) {
QRgb *scanLine = (QRgb*)im.scanLine(y); QRgb *scanLine = (QRgb *)im.scanLine(y);
for (int x=0; x<im.width(); ++x) { for (int x = 0; x < im.width(); ++x) {
QRgb pixel = *scanLine; QRgb pixel = *scanLine;
char intensity = qGray(pixel); char intensity = qGray(pixel);
*scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel)); *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
++scanLine; ++scanLine;
@ -459,39 +471,46 @@ void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect re
int left, int top, int right, int bottom) int left, int top, int right, int bottom)
{ {
QSize size = img.size(); QSize size = img.size();
if (top > 0) { //top
painter->drawImage(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), img, if (top > 0) { // top
QRect(left, 0, size.width() -right - left, top)); painter->drawImage(QRect(rect.left() + left, rect.top(), rect.width() - right - left, top), img,
if (left > 0) //top-left QRect(left, 0, size.width() - right - left, top));
if (left > 0) { // top-left
painter->drawImage(QRect(rect.left(), rect.top(), left, top), img, painter->drawImage(QRect(rect.left(), rect.top(), left, top), img,
QRect(0, 0, left, top)); QRect(0, 0, left, top));
if (right > 0) //top-right }
if (right > 0) { // top-right
painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top(), right, top), img, painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top(), right, top), img,
QRect(size.width() - right, 0, right, top)); QRect(size.width() - right, 0, right, top));
}
} }
//left // left
if (left > 0) if (left > 0) {
painter->drawImage(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), img, painter->drawImage(QRect(rect.left(), rect.top() + top, left, rect.height() - top - bottom), img,
QRect(0, top, left, size.height() - bottom - top)); QRect(0, top, left, size.height() - bottom - top));
//center }
painter->drawImage(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left, // center
painter->drawImage(QRect(rect.left() + left, rect.top() + top, rect.width() - right - left,
rect.height() - bottom - top), img, rect.height() - bottom - top), img,
QRect(left, top, size.width() -right -left, QRect(left, top, size.width() - right - left,
size.height() - bottom - top)); size.height() - bottom - top));
if (right > 0) //right if (right > 0) { // right
painter->drawImage(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), img, painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top() + top, right, rect.height() - top - bottom), img,
QRect(size.width() - right, top, right, size.height() - bottom - top)); QRect(size.width() - right, top, right, size.height() - bottom - top));
if (bottom > 0) { //bottom }
painter->drawImage(QRect(rect.left() +left, rect.top() + rect.height() - bottom, if (bottom > 0) { // bottom
painter->drawImage(QRect(rect.left() + left, rect.top() + rect.height() - bottom,
rect.width() - right - left, bottom), img, rect.width() - right - left, bottom), img,
QRect(left, size.height() - bottom, QRect(left, size.height() - bottom,
size.width() - right - left, bottom)); size.width() - right - left, bottom));
if (left > 0) //bottom-left if (left > 0) { // bottom-left
painter->drawImage(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), img, painter->drawImage(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), img,
QRect(0, size.height() - bottom, left, bottom)); QRect(0, size.height() - bottom, left, bottom));
if (right > 0) //bottom-right }
painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), img, if (right > 0) { // bottom-right
QRect(size.width() - right, size.height() - bottom, right, bottom)); painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), img,
QRect(size.width() - right, size.height() - bottom, right, bottom));
}
} }
} }
@ -499,12 +518,13 @@ void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect re
void StyleHelper::tintImage(QImage &img, const QColor &tintColor) void StyleHelper::tintImage(QImage &img, const QColor &tintColor)
{ {
QPainter p(&img); QPainter p(&img);
p.setCompositionMode(QPainter::CompositionMode_Screen); p.setCompositionMode(QPainter::CompositionMode_Screen);
for (int x = 0; x < img.width(); ++x) { for (int x = 0; x < img.width(); ++x) {
for (int y = 0; y < img.height(); ++y) { for (int y = 0; y < img.height(); ++y) {
QRgb rgbColor = img.pixel(x, y); QRgb rgbColor = img.pixel(x, y);
int alpha = qAlpha(rgbColor); int alpha = qAlpha(rgbColor);
QColor c = QColor(rgbColor); QColor c = QColor(rgbColor);
if (alpha > 0) { if (alpha > 0) {
@ -522,10 +542,10 @@ QLinearGradient StyleHelper::statusBarGradient(const QRect &statusBarRect)
{ {
QLinearGradient grad(statusBarRect.topLeft(), QPoint(statusBarRect.center().x(), statusBarRect.bottom())); QLinearGradient grad(statusBarRect.topLeft(), QPoint(statusBarRect.center().x(), statusBarRect.bottom()));
QColor startColor = shadowColor().darker(164); QColor startColor = shadowColor().darker(164);
QColor endColor = baseColor().darker(130); QColor endColor = baseColor().darker(130);
grad.setColorAt(0, startColor); grad.setColorAt(0, startColor);
grad.setColorAt(1, endColor); grad.setColorAt(1, endColor);
return grad; return grad;
} }
} // namespace Utils } // namespace Utils

View File

@ -45,29 +45,43 @@ QT_END_NAMESPACE
// Helper class holding all custom color values // Helper class holding all custom color values
namespace Utils { namespace Utils {
class QTCREATOR_UTILS_EXPORT StyleHelper class QTCREATOR_UTILS_EXPORT StyleHelper {
{
public: public:
static const unsigned int DEFAULT_BASE_COLOR = 0x666666; static const unsigned int DEFAULT_BASE_COLOR = 0x666666;
static const int progressFadeAnimationDuration = 600; static const int progressFadeAnimationDuration = 600;
// Height of the project explorer navigation bar // Height of the project explorer navigation bar
static int navigationWidgetHeight() { return 24; } static int navigationWidgetHeight()
{
return 24;
}
static qreal sidebarFontSize(); static qreal sidebarFontSize();
static QPalette sidebarFontPalette(const QPalette &original); static QPalette sidebarFontPalette(const QPalette &original);
// This is our color table, all colors derive from baseColor // This is our color table, all colors derive from baseColor
static QColor requestedBaseColor() { return m_requestedBaseColor; } static QColor requestedBaseColor()
{
return m_requestedBaseColor;
}
static QColor baseColor(bool lightColored = false); static QColor baseColor(bool lightColored = false);
static QColor panelTextColor(bool lightColored = false); static QColor panelTextColor(bool lightColored = false);
static QColor highlightColor(bool lightColored = false); static QColor highlightColor(bool lightColored = false);
static QColor shadowColor(bool lightColored = false); static QColor shadowColor(bool lightColored = false);
static QColor borderColor(bool lightColored = false); static QColor borderColor(bool lightColored = false);
static QColor buttonTextColor() { return QColor(0x4c4c4c); } static QColor buttonTextColor()
{
return QColor(0x4c4c4c);
}
static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50); static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50);
static QColor sidebarHighlight() { return QColor(255, 255, 255, 40); } static QColor sidebarHighlight()
static QColor sidebarShadow() { return QColor(0, 0, 0, 40); } {
return QColor(255, 255, 255, 40);
}
static QColor sidebarShadow()
{
return QColor(0, 0, 0, 40);
}
// Sets the base color and makes sure all top level widgets are updated // Sets the base color and makes sure all top level widgets are updated
static void setBaseColor(const QColor &color); static void setBaseColor(const QColor &color);
@ -79,13 +93,16 @@ public:
static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false); static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false);
static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false); static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false);
static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect);
static bool usePixmapCache() { return true; } static bool usePixmapCache()
{
return true;
}
static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode,
int dipRadius = 3, const QColor &color = QColor(0, 0, 0, 130), int dipRadius = 3, const QColor &color = QColor(0, 0, 0, 130),
const QPoint &dipOffset = QPoint(1, -2)); const QPoint &dipOffset = QPoint(1, -2));
static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect, static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
int left = 0, int top = 0, int right = 0, int bottom = 0); int left = 0, int top = 0, int right = 0, int bottom = 0);
static void tintImage(QImage &img, const QColor &tintColor); static void tintImage(QImage &img, const QColor &tintColor);
static QLinearGradient statusBarGradient(const QRect &statusBarRect); static QLinearGradient statusBarGradient(const QRect &statusBarRect);
@ -94,6 +111,5 @@ private:
static QColor m_baseColor; static QColor m_baseColor;
static QColor m_requestedBaseColor; static QColor m_requestedBaseColor;
}; };
} // namespace Utils } // namespace Utils
#endif // STYLEHELPER_H #endif // STYLEHELPER_H

View File

@ -44,11 +44,10 @@
#include <QTimer> #include <QTimer>
namespace Core { namespace Core {
class IConnection; class IConnection;
namespace Internal { namespace Internal {
class MainWindow; class MainWindow;
} // namespace Internal } // namespace Internal
class DevListItem { class DevListItem {

View File

@ -201,7 +201,7 @@ const char *const ICON_PREV = ":/core/images/prev.png";
const char *const ICON_DIR = ":/core/images/dir.png"; const char *const ICON_DIR = ":/core/images/dir.png";
const char *const ICON_CLEAN_PANE = ":/core/images/clean_pane_small.png"; const char *const ICON_CLEAN_PANE = ":/core/images/clean_pane_small.png";
const char *const ICON_CLEAR = ":/core/images/clear.png"; const char *const ICON_CLEAR = ":/core/images/clear.png";
const char *const ICON_CLOSE = ":/core/images/closebutton.png"; const char *const ICON_CLOSE = ":/core/images/closebutton.png";
const char *const ICON_FIND = ":/core/images/find.png"; const char *const ICON_FIND = ":/core/images/find.png";
const char *const ICON_FINDNEXT = ":/core/images/findnext.png"; const char *const ICON_FINDNEXT = ":/core/images/findnext.png";
const char *const ICON_REPLACE = ":/core/images/replace.png"; const char *const ICON_REPLACE = ":/core/images/replace.png";

View File

@ -46,7 +46,7 @@
using namespace Core; using namespace Core;
using namespace Internal; using namespace Internal;
const int FancyTabBar::m_rounding = 22; const int FancyTabBar::m_rounding = 22;
const int FancyTabBar::m_textPadding = 4; const int FancyTabBar::m_textPadding = 4;
void FancyTab::fadeIn() void FancyTab::fadeIn()
@ -74,7 +74,7 @@ void FancyTab::setFader(float value)
FancyTabBar::FancyTabBar(QWidget *parent) FancyTabBar::FancyTabBar(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
m_hoverIndex = -1; m_hoverIndex = -1;
m_currentIndex = -1; m_currentIndex = -1;
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
setStyle(QStyleFactory::create(QLatin1String("windows"))); setStyle(QStyleFactory::create(QLatin1String("windows")));
@ -96,16 +96,18 @@ FancyTabBar::~FancyTabBar()
QSize FancyTabBar::tabSizeHint(bool minimum) const QSize FancyTabBar::tabSizeHint(bool minimum) const
{ {
QFont boldFont(font()); QFont boldFont(font());
boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
boldFont.setBold(true); boldFont.setBold(true);
QFontMetrics fm(boldFont); QFontMetrics fm(boldFont);
int spacing = 8; int spacing = 8;
int width = 60 + spacing + 2; int width = 60 + spacing + 2;
int maxLabelwidth = 0; int maxLabelwidth = 0;
for (int tab=0 ; tab<count() ;++tab) { for (int tab = 0; tab < count(); ++tab) {
int width = fm.width(tabText(tab)); int width = fm.width(tabText(tab));
if (width > maxLabelwidth) if (width > maxLabelwidth) {
maxLabelwidth = width; maxLabelwidth = width;
}
} }
int iconHeight = minimum ? 0 : 32; int iconHeight = minimum ? 0 : 32;
return QSize(qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height()); return QSize(qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height());
@ -116,19 +118,23 @@ void FancyTabBar::paintEvent(QPaintEvent *event)
Q_UNUSED(event) Q_UNUSED(event)
QPainter p(this); QPainter p(this);
for (int i = 0; i < count(); ++i) for (int i = 0; i < count(); ++i) {
if (i != currentIndex()) if (i != currentIndex()) {
paintTab(&p, i); paintTab(&p, i);
}
}
// paint active tab last, since it overlaps the neighbors // paint active tab last, since it overlaps the neighbors
if (currentIndex() != -1) if (currentIndex() != -1) {
paintTab(&p, currentIndex()); paintTab(&p, currentIndex());
}
} }
// Handle hover events for mouse fade ins // Handle hover events for mouse fade ins
void FancyTabBar::mouseMoveEvent(QMouseEvent *e) void FancyTabBar::mouseMoveEvent(QMouseEvent *e)
{ {
int newHover = -1; int newHover = -1;
for (int i = 0; i < count(); ++i) { for (int i = 0; i < count(); ++i) {
QRect area = tabRect(i); QRect area = tabRect(i);
if (area.contains(e->pos())) { if (area.contains(e->pos())) {
@ -136,11 +142,13 @@ void FancyTabBar::mouseMoveEvent(QMouseEvent *e)
break; break;
} }
} }
if (newHover == m_hoverIndex) if (newHover == m_hoverIndex) {
return; return;
}
if (validIndex(m_hoverIndex)) if (validIndex(m_hoverIndex)) {
m_tabs[m_hoverIndex]->fadeOut(); m_tabs[m_hoverIndex]->fadeOut();
}
m_hoverIndex = newHover; m_hoverIndex = newHover;
@ -156,7 +164,7 @@ bool FancyTabBar::event(QEvent *event)
if (validIndex(m_hoverIndex)) { if (validIndex(m_hoverIndex)) {
QString tt = tabToolTip(m_hoverIndex); QString tt = tabToolTip(m_hoverIndex);
if (!tt.isEmpty()) { if (!tt.isEmpty()) {
QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), tt, this); QToolTip::showText(static_cast<QHelpEvent *>(event)->globalPos(), tt, this);
return true; return true;
} }
} }
@ -168,7 +176,7 @@ bool FancyTabBar::event(QEvent *event)
void FancyTabBar::enterEvent(QEvent *e) void FancyTabBar::enterEvent(QEvent *e)
{ {
Q_UNUSED(e) Q_UNUSED(e)
m_hoverRect = QRect(); m_hoverRect = QRect();
m_hoverIndex = -1; m_hoverIndex = -1;
} }
@ -177,8 +185,8 @@ void FancyTabBar::leaveEvent(QEvent *e)
{ {
Q_UNUSED(e) Q_UNUSED(e)
m_hoverIndex = -1; m_hoverIndex = -1;
m_hoverRect = QRect(); m_hoverRect = QRect();
for (int i = 0 ; i < m_tabs.count() ; ++i) { for (int i = 0; i < m_tabs.count(); ++i) {
m_tabs[i]->fadeOut(); m_tabs[i]->fadeOut();
} }
} }
@ -186,12 +194,14 @@ void FancyTabBar::leaveEvent(QEvent *e)
QSize FancyTabBar::sizeHint() const QSize FancyTabBar::sizeHint() const
{ {
QSize sh = tabSizeHint(); QSize sh = tabSizeHint();
return QSize(sh.width(), sh.height() * m_tabs.count()); return QSize(sh.width(), sh.height() * m_tabs.count());
} }
QSize FancyTabBar::minimumSizeHint() const QSize FancyTabBar::minimumSizeHint() const
{ {
QSize sh = tabSizeHint(true); QSize sh = tabSizeHint(true);
return QSize(sh.width(), sh.height() * m_tabs.count()); return QSize(sh.width(), sh.height() * m_tabs.count());
} }
@ -199,11 +209,11 @@ QRect FancyTabBar::tabRect(int index) const
{ {
QSize sh = tabSizeHint(); QSize sh = tabSizeHint();
if (sh.height() * m_tabs.count() > height()) if (sh.height() * m_tabs.count() > height()) {
sh.setHeight(height() / m_tabs.count()); sh.setHeight(height() / m_tabs.count());
}
return QRect(0, index * sh.height(), sh.width(), sh.height()); return QRect(0, index * sh.height(), sh.width(), sh.height());
} }
// This keeps the sidebar responsive since // This keeps the sidebar responsive since
@ -219,7 +229,6 @@ void FancyTabBar::mousePressEvent(QMouseEvent *e)
e->accept(); e->accept();
for (int index = 0; index < m_tabs.count(); ++index) { for (int index = 0; index < m_tabs.count(); ++index) {
if (tabRect(index).contains(e->pos())) { if (tabRect(index).contains(e->pos())) {
if (isTabEnabled(index)) { if (isTabEnabled(index)) {
m_currentIndex = index; m_currentIndex = index;
update(); update();
@ -238,12 +247,12 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
} }
painter->save(); painter->save();
QRect rect = tabRect(tabIndex); QRect rect = tabRect(tabIndex);
bool selected = (tabIndex == m_currentIndex); bool selected = (tabIndex == m_currentIndex);
bool enabled = isTabEnabled(tabIndex); bool enabled = isTabEnabled(tabIndex);
if (selected) { if (selected) {
//background // background
painter->save(); painter->save();
QLinearGradient grad(rect.topLeft(), rect.topRight()); QLinearGradient grad(rect.topLeft(), rect.topRight());
grad.setColorAt(0, QColor(255, 255, 255, 140)); grad.setColorAt(0, QColor(255, 255, 255, 140));
@ -251,21 +260,21 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
painter->fillRect(rect.adjusted(0, 0, 0, -1), grad); painter->fillRect(rect.adjusted(0, 0, 0, -1), grad);
painter->restore(); painter->restore();
//shadows // shadows
painter->setPen(QColor(0, 0, 0, 110)); painter->setPen(QColor(0, 0, 0, 110));
painter->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1)); painter->drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1));
painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->drawLine(rect.bottomLeft(), rect.bottomRight());
painter->setPen(QColor(0, 0, 0, 40)); painter->setPen(QColor(0, 0, 0, 40));
painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topLeft(), rect.bottomLeft());
//highlights // highlights
painter->setPen(QColor(255, 255, 255, 50)); painter->setPen(QColor(255, 255, 255, 50));
painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2)); painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2));
painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1)); painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0, 1));
painter->setPen(QColor(255, 255, 255, 40)); painter->setPen(QColor(255, 255, 255, 40));
painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight());
painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)); painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1));
painter->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1)); painter->drawLine(rect.bottomLeft() + QPoint(0, -1), rect.bottomRight() - QPoint(0, 1));
} }
QString tabText(this->tabText(tabIndex)); QString tabText(this->tabText(tabIndex));
@ -299,8 +308,9 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
painter->restore(); painter->restore();
} }
if (!enabled) if (!enabled) {
painter->setOpacity(0.7); painter->setOpacity(0.7);
}
if (drawIcon) { if (drawIcon) {
int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height();
@ -313,7 +323,8 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
painter->restore(); painter->restore();
} }
void FancyTabBar::setCurrentIndex(int index) { void FancyTabBar::setCurrentIndex(int index)
{
if (isTabEnabled(index)) { if (isTabEnabled(index)) {
m_currentIndex = index; m_currentIndex = index;
update(); update();
@ -337,8 +348,9 @@ bool FancyTabBar::isTabEnabled(int index) const
Q_ASSERT(index < m_tabs.size()); Q_ASSERT(index < m_tabs.size());
Q_ASSERT(index >= 0); Q_ASSERT(index >= 0);
if (index < m_tabs.size() && index >= 0) if (index < m_tabs.size() && index >= 0) {
return m_tabs[index]->enabled; return m_tabs[index]->enabled;
}
return false; return false;
} }
@ -348,11 +360,10 @@ bool FancyTabBar::isTabEnabled(int index) const
// FancyColorButton // FancyColorButton
////// //////
class FancyColorButton : public QWidget class FancyColorButton : public QWidget {
{
public: public:
FancyColorButton(QWidget *parent) FancyColorButton(QWidget *parent)
: m_parent(parent) : m_parent(parent)
{ {
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
} }
@ -361,8 +372,9 @@ public:
{ {
if (ev->modifiers() & Qt::ShiftModifier) { if (ev->modifiers() & Qt::ShiftModifier) {
QColor color = QColorDialog::getColor(Utils::StyleHelper::requestedBaseColor(), m_parent); QColor color = QColorDialog::getColor(Utils::StyleHelper::requestedBaseColor(), m_parent);
if (color.isValid()) if (color.isValid()) {
Utils::StyleHelper::setBaseColor(color); Utils::StyleHelper::setBaseColor(color);
}
} }
} }
private: private:
@ -384,7 +396,7 @@ FancyTabWidget::FancyTabWidget(QWidget *parent)
selectionLayout->setMargin(0); selectionLayout->setMargin(0);
Utils::StyledBar *bar = new Utils::StyledBar; Utils::StyledBar *bar = new Utils::StyledBar;
QHBoxLayout *layout = new QHBoxLayout(bar); QHBoxLayout *layout = new QHBoxLayout(bar);
layout->setMargin(0); layout->setMargin(0);
layout->setSpacing(0); layout->setSpacing(0);
layout->addWidget(new FancyColorButton(this)); layout->addWidget(new FancyColorButton(this));
@ -407,7 +419,7 @@ FancyTabWidget::FancyTabWidget(QWidget *parent)
selectionLayout->addWidget(m_cornerWidgetContainer, 0); selectionLayout->addWidget(m_cornerWidgetContainer, 0);
m_modesStack = new QStackedLayout; m_modesStack = new QStackedLayout;
m_statusBar = new QStatusBar; m_statusBar = new QStatusBar;
m_statusBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); m_statusBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
QVBoxLayout *vlayout = new QVBoxLayout; QVBoxLayout *vlayout = new QVBoxLayout;
@ -451,6 +463,7 @@ void FancyTabWidget::removeTab(int index)
void FancyTabWidget::setBackgroundBrush(const QBrush &brush) void FancyTabWidget::setBackgroundBrush(const QBrush &brush)
{ {
QPalette pal = m_tabBar->palette(); QPalette pal = m_tabBar->palette();
pal.setBrush(QPalette::Mid, brush); pal.setBrush(QPalette::Mid, brush);
m_tabBar->setPalette(pal); m_tabBar->setPalette(pal);
pal = m_cornerWidgetContainer->palette(); pal = m_cornerWidgetContainer->palette();
@ -479,6 +492,7 @@ void FancyTabWidget::paintEvent(QPaintEvent *event)
void FancyTabWidget::insertCornerWidget(int pos, QWidget *widget) void FancyTabWidget::insertCornerWidget(int pos, QWidget *widget)
{ {
QVBoxLayout *layout = static_cast<QVBoxLayout *>(m_cornerWidgetContainer->layout()); QVBoxLayout *layout = static_cast<QVBoxLayout *>(m_cornerWidgetContainer->layout());
layout->insertWidget(pos, widget); layout->insertWidget(pos, widget);
} }
@ -504,13 +518,15 @@ QStatusBar *FancyTabWidget::statusBar() const
void FancyTabWidget::setCurrentIndex(int index) void FancyTabWidget::setCurrentIndex(int index)
{ {
if (m_tabBar->isTabEnabled(index)) if (m_tabBar->isTabEnabled(index)) {
m_tabBar->setCurrentIndex(index); m_tabBar->setCurrentIndex(index);
}
} }
void FancyTabWidget::showWidget(int index) void FancyTabWidget::showWidget(int index)
{ {
emit currentAboutToShow(index); emit currentAboutToShow(index);
m_modesStack->setCurrentIndex(index); m_modesStack->setCurrentIndex(index);
emit currentChanged(index); emit currentChanged(index);
} }

View File

@ -43,18 +43,18 @@ QT_END_NAMESPACE
namespace Core { namespace Core {
namespace Internal { namespace Internal {
class FancyTab : public QObject {
class FancyTab : public QObject Q_OBJECT Q_PROPERTY(float fader READ fader WRITE setFader)
{
Q_OBJECT
Q_PROPERTY(float fader READ fader WRITE setFader)
public: public:
FancyTab(QWidget *tabbar) : enabled(false), tabbar(tabbar), m_fader(0) { FancyTab(QWidget *tabbar) : enabled(false), tabbar(tabbar), m_fader(0)
{
animator.setPropertyName("fader"); animator.setPropertyName("fader");
animator.setTargetObject(this); animator.setTargetObject(this);
} }
float fader() { return m_fader; } float fader()
{
return m_fader;
}
void setFader(float value); void setFader(float value);
void fadeIn(); void fadeIn();
@ -71,8 +71,7 @@ private:
float m_fader; float m_fader;
}; };
class FancyTabBar : public QWidget class FancyTabBar : public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
@ -87,7 +86,10 @@ public:
void mouseMoveEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *);
void enterEvent(QEvent *); void enterEvent(QEvent *);
void leaveEvent(QEvent *); void leaveEvent(QEvent *);
bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); } bool validIndex(int index) const
{
return index >= 0 && index < m_tabs.count();
}
QSize sizeHint() const; QSize sizeHint() const;
QSize minimumSizeHint() const; QSize minimumSizeHint() const;
@ -95,28 +97,50 @@ public:
void setTabEnabled(int index, bool enable); void setTabEnabled(int index, bool enable);
bool isTabEnabled(int index) const; bool isTabEnabled(int index) const;
void insertTab(int index, const QIcon &icon, const QString &label) { void insertTab(int index, const QIcon &icon, const QString &label)
{
FancyTab *tab = new FancyTab(this); FancyTab *tab = new FancyTab(this);
tab->icon = icon; tab->icon = icon;
tab->text = label; tab->text = label;
m_tabs.insert(index, tab); m_tabs.insert(index, tab);
updateGeometry(); updateGeometry();
} }
void setEnabled(int index, bool enabled); void setEnabled(int index, bool enabled);
void removeTab(int index) { void removeTab(int index)
{
FancyTab *tab = m_tabs.takeAt(index); FancyTab *tab = m_tabs.takeAt(index);
delete tab; delete tab;
updateGeometry(); updateGeometry();
} }
void setCurrentIndex(int index); void setCurrentIndex(int index);
int currentIndex() const { return m_currentIndex; } int currentIndex() const
{
return m_currentIndex;
}
void setTabToolTip(int index, QString toolTip) { m_tabs[index]->toolTip = toolTip; } void setTabToolTip(int index, QString toolTip)
QString tabToolTip(int index) const { return m_tabs.at(index)->toolTip; } {
m_tabs[index]->toolTip = toolTip;
}
QString tabToolTip(int index) const
{
return m_tabs.at(index)->toolTip;
}
QIcon tabIcon(int index) const { return m_tabs.at(index)->icon; } QIcon tabIcon(int index) const
QString tabText(int index) const { return m_tabs.at(index)->text; } {
int count() const {return m_tabs.count(); } return m_tabs.at(index)->icon;
}
QString tabText(int index) const
{
return m_tabs.at(index)->text;
}
int count() const
{
return m_tabs.count();
}
QRect tabRect(int index) const; QRect tabRect(int index) const;
signals: signals:
@ -131,14 +155,12 @@ private:
QRect m_hoverRect; QRect m_hoverRect;
int m_hoverIndex; int m_hoverIndex;
int m_currentIndex; int m_currentIndex;
QList<FancyTab*> m_tabs; QList<FancyTab *> m_tabs;
QTimer m_triggerTimer; QTimer m_triggerTimer;
QSize tabSizeHint(bool minimum = false) const; QSize tabSizeHint(bool minimum = false) const;
}; };
class FancyTabWidget : public QWidget class FancyTabWidget : public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
@ -180,7 +202,6 @@ private:
QWidget *m_selectionWidget; QWidget *m_selectionWidget;
QStatusBar *m_statusBar; QStatusBar *m_statusBar;
}; };
} // namespace Internal } // namespace Internal
} // namespace Core } // namespace Core

View File

@ -59,10 +59,12 @@ const QStyle::State State_Animating = QStyle::State(0x00000040);
bool styleEnabled(const QWidget *widget) bool styleEnabled(const QWidget *widget)
{ {
const QWidget *p = widget; const QWidget *p = widget;
while (p) { while (p) {
if (p->property("_q_custom_style_disabled").toBool()) if (p->property("_q_custom_style_disabled").toBool()) {
return false; return false;
p = p->parentWidget(); }
p = p->parentWidget();
} }
return true; return true;
} }
@ -70,26 +72,31 @@ bool styleEnabled(const QWidget *widget)
// Consider making this a QStyle state // Consider making this a QStyle state
bool panelWidget(const QWidget *widget) bool panelWidget(const QWidget *widget)
{ {
if (!widget) if (!widget) {
return false; return false;
}
// Do not style dialogs or explicitly ignored widgets // Do not style dialogs or explicitly ignored widgets
if ((widget->window()->windowFlags() & Qt::WindowType_Mask) == Qt::Dialog) if ((widget->window()->windowFlags() & Qt::WindowType_Mask) == Qt::Dialog) {
return false; return false;
}
if (qobject_cast<const Utils::FancyMainWindow *>(widget)) if (qobject_cast<const Utils::FancyMainWindow *>(widget)) {
return true; return true;
}
if (qobject_cast<const QTabBar *>(widget)) if (qobject_cast<const QTabBar *>(widget)) {
return styleEnabled(widget); return styleEnabled(widget);
}
const QWidget *p = widget; const QWidget *p = widget;
while (p) { while (p) {
if (qobject_cast<const QToolBar *>(p) || if (qobject_cast<const QToolBar *>(p) ||
qobject_cast<const QStatusBar *>(p) || qobject_cast<const QStatusBar *>(p) ||
qobject_cast<const QMenuBar *>(p) || qobject_cast<const QMenuBar *>(p) ||
p->property("panelwidget").toBool()) p->property("panelwidget").toBool()) {
return styleEnabled(widget); return styleEnabled(widget);
}
p = p->parentWidget(); p = p->parentWidget();
} }
return false; return false;
@ -98,24 +105,26 @@ bool panelWidget(const QWidget *widget)
// Consider making this a QStyle state // Consider making this a QStyle state
bool lightColored(const QWidget *widget) bool lightColored(const QWidget *widget)
{ {
if (!widget) if (!widget) {
return false; return false;
}
// Don't style dialogs or explicitly ignored widgets // Don't style dialogs or explicitly ignored widgets
if ((widget->window()->windowFlags() & Qt::WindowType_Mask) == Qt::Dialog) if ((widget->window()->windowFlags() & Qt::WindowType_Mask) == Qt::Dialog) {
return false; return false;
}
const QWidget *p = widget; const QWidget *p = widget;
while (p) { while (p) {
if (p->property("lightColored").toBool()) if (p->property("lightColored").toBool()) {
return true; return true;
}
p = p->parentWidget(); p = p->parentWidget();
} }
return false; return false;
} }
class ManhattanStylePrivate class ManhattanStylePrivate {
{
public: public:
explicit ManhattanStylePrivate(); explicit ManhattanStylePrivate();
void init(); void init();
@ -133,14 +142,12 @@ ManhattanStylePrivate::ManhattanStylePrivate() :
lineeditImage_disabled(QLatin1String(":/core/images/inputfield_disabled.png")), lineeditImage_disabled(QLatin1String(":/core/images/inputfield_disabled.png")),
extButtonPixmap(QLatin1String(":/core/images/extension.png")), extButtonPixmap(QLatin1String(":/core/images/extension.png")),
closeButtonPixmap(QLatin1String(Core::Constants::ICON_CLOSE)) closeButtonPixmap(QLatin1String(Core::Constants::ICON_CLOSE))
{ {}
}
ManhattanStyle::ManhattanStyle(const QString &baseStyleName) ManhattanStyle::ManhattanStyle(const QString &baseStyleName)
: QProxyStyle(QStyleFactory::create(baseStyleName)), : QProxyStyle(QStyleFactory::create(baseStyleName)),
d(new ManhattanStylePrivate()) d(new ManhattanStylePrivate())
{ {}
}
ManhattanStyle::~ManhattanStyle() ManhattanStyle::~ManhattanStyle()
{ {
@ -158,10 +165,11 @@ QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *op
{ {
QSize newSize = QProxyStyle::sizeFromContents(type, option, size, widget); QSize newSize = QProxyStyle::sizeFromContents(type, option, size, widget);
if (type == CT_Splitter && widget && widget->property("minisplitter").toBool()) if (type == CT_Splitter && widget && widget->property("minisplitter").toBool()) {
return QSize(1, 1); return QSize(1, 1);
else if (type == CT_ComboBox && panelWidget(widget)) } else if (type == CT_ComboBox && panelWidget(widget)) {
newSize += QSize(14, 0); newSize += QSize(14, 0);
}
return newSize; return newSize;
} }
@ -185,37 +193,44 @@ QStyle::SubControl ManhattanStyle::hitTestComplexControl(ComplexControl control,
int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
{ {
int retval = 0; int retval = 0;
retval = QProxyStyle::pixelMetric(metric, option, widget); retval = QProxyStyle::pixelMetric(metric, option, widget);
switch (metric) { switch (metric) {
case PM_SplitterWidth: case PM_SplitterWidth:
if (widget && widget->property("minisplitter").toBool()) if (widget && widget->property("minisplitter").toBool()) {
retval = 1; retval = 1;
}
break; break;
case PM_ToolBarIconSize: case PM_ToolBarIconSize:
if (panelWidget(widget)) if (panelWidget(widget)) {
retval = 16; retval = 16;
}
break; break;
case PM_DockWidgetHandleExtent: case PM_DockWidgetHandleExtent:
case PM_DockWidgetSeparatorExtent: case PM_DockWidgetSeparatorExtent:
return 1; return 1;
case PM_MenuPanelWidth: case PM_MenuPanelWidth:
case PM_MenuBarHMargin: case PM_MenuBarHMargin:
case PM_MenuBarVMargin: case PM_MenuBarVMargin:
case PM_ToolBarFrameWidth: case PM_ToolBarFrameWidth:
if (panelWidget(widget)) if (panelWidget(widget)) {
retval = 1; retval = 1;
}
break; break;
case PM_ButtonShiftVertical: case PM_ButtonShiftVertical:
case PM_ButtonShiftHorizontal: case PM_ButtonShiftHorizontal:
case PM_MenuBarPanelWidth: case PM_MenuBarPanelWidth:
case PM_ToolBarItemMargin: case PM_ToolBarItemMargin:
case PM_ToolBarItemSpacing: case PM_ToolBarItemSpacing:
if (panelWidget(widget)) if (panelWidget(widget)) {
retval = 0; retval = 0;
}
break; break;
case PM_DefaultFrameWidth: case PM_DefaultFrameWidth:
if (qobject_cast<const QLineEdit*>(widget) && panelWidget(widget)) if (qobject_cast<const QLineEdit *>(widget) && panelWidget(widget)) {
return 1; return 1;
}
break; break;
default: default:
break; break;
@ -242,6 +257,7 @@ QPalette panelPalette(const QPalette &oldPalette, bool lightColored = false)
{ {
QColor color = Utils::StyleHelper::panelTextColor(lightColored); QColor color = Utils::StyleHelper::panelTextColor(lightColored);
QPalette pal = oldPalette; QPalette pal = oldPalette;
pal.setBrush(QPalette::All, QPalette::WindowText, color); pal.setBrush(QPalette::All, QPalette::WindowText, color);
pal.setBrush(QPalette::All, QPalette::ButtonText, color); pal.setBrush(QPalette::All, QPalette::ButtonText, color);
pal.setBrush(QPalette::All, QPalette::Foreground, color); pal.setBrush(QPalette::All, QPalette::Foreground, color);
@ -258,33 +274,31 @@ void ManhattanStyle::polish(QWidget *widget)
// OxygenStyle forces a rounded widget mask on toolbars and dock widgets // OxygenStyle forces a rounded widget mask on toolbars and dock widgets
if (baseStyle()->inherits("OxygenStyle") || baseStyle()->inherits("Oxygen::Style")) { if (baseStyle()->inherits("OxygenStyle") || baseStyle()->inherits("Oxygen::Style")) {
if (qobject_cast<QToolBar*>(widget) || qobject_cast<QDockWidget*>(widget)) { if (qobject_cast<QToolBar *>(widget) || qobject_cast<QDockWidget *>(widget)) {
widget->removeEventFilter(baseStyle()); widget->removeEventFilter(baseStyle());
widget->setContentsMargins(0, 0, 0, 0); widget->setContentsMargins(0, 0, 0, 0);
} }
} }
if (panelWidget(widget)) { if (panelWidget(widget)) {
// Oxygen and possibly other styles override this // Oxygen and possibly other styles override this
if (qobject_cast<QDockWidget*>(widget)) if (qobject_cast<QDockWidget *>(widget)) {
widget->setContentsMargins(0, 0, 0, 0); widget->setContentsMargins(0, 0, 0, 0);
}
widget->setAttribute(Qt::WA_LayoutUsesWidgetRect, true); widget->setAttribute(Qt::WA_LayoutUsesWidgetRect, true);
if (qobject_cast<QToolButton*>(widget)) { if (qobject_cast<QToolButton *>(widget)) {
widget->setAttribute(Qt::WA_Hover); widget->setAttribute(Qt::WA_Hover);
widget->setMaximumHeight(Utils::StyleHelper::navigationWidgetHeight() - 2); widget->setMaximumHeight(Utils::StyleHelper::navigationWidgetHeight() - 2);
} } else if (qobject_cast<QLineEdit *>(widget)) {
else if (qobject_cast<QLineEdit*>(widget)) {
widget->setAttribute(Qt::WA_Hover); widget->setAttribute(Qt::WA_Hover);
widget->setMaximumHeight(Utils::StyleHelper::navigationWidgetHeight() - 2); widget->setMaximumHeight(Utils::StyleHelper::navigationWidgetHeight() - 2);
} } else if (qobject_cast<QLabel *>(widget)) {
else if (qobject_cast<QLabel*>(widget))
widget->setPalette(panelPalette(widget->palette())); widget->setPalette(panelPalette(widget->palette()));
else if (widget->property("panelwidget_singlerow").toBool()) } else if (widget->property("panelwidget_singlerow").toBool()) {
widget->setFixedHeight(Utils::StyleHelper::navigationWidgetHeight()); widget->setFixedHeight(Utils::StyleHelper::navigationWidgetHeight());
else if (qobject_cast<QStatusBar*>(widget)) } else if (qobject_cast<QStatusBar *>(widget)) {
widget->setFixedHeight(Utils::StyleHelper::navigationWidgetHeight() + 2); widget->setFixedHeight(Utils::StyleHelper::navigationWidgetHeight() + 2);
else if (qobject_cast<QComboBox*>(widget)) { } else if (qobject_cast<QComboBox *>(widget)) {
widget->setMaximumHeight(Utils::StyleHelper::navigationWidgetHeight() - 2); widget->setMaximumHeight(Utils::StyleHelper::navigationWidgetHeight() - 2);
widget->setAttribute(Qt::WA_Hover); widget->setAttribute(Qt::WA_Hover);
} }
@ -294,14 +308,16 @@ void ManhattanStyle::polish(QWidget *widget)
void ManhattanStyle::unpolish(QWidget *widget) void ManhattanStyle::unpolish(QWidget *widget)
{ {
QProxyStyle::unpolish(widget); QProxyStyle::unpolish(widget);
if (panelWidget(widget)) { if (panelWidget(widget)) {
widget->setAttribute(Qt::WA_LayoutUsesWidgetRect, false); widget->setAttribute(Qt::WA_LayoutUsesWidgetRect, false);
if (qobject_cast<QTabBar*>(widget)) if (qobject_cast<QTabBar *>(widget)) {
widget->setAttribute(Qt::WA_Hover, false); widget->setAttribute(Qt::WA_Hover, false);
else if (qobject_cast<QToolBar*>(widget)) } else if (qobject_cast<QToolBar *>(widget)) {
widget->setAttribute(Qt::WA_Hover, false); widget->setAttribute(Qt::WA_Hover, false);
else if (qobject_cast<QComboBox*>(widget)) } else if (qobject_cast<QComboBox *>(widget)) {
widget->setAttribute(Qt::WA_Hover, false); widget->setAttribute(Qt::WA_Hover, false);
}
} }
} }
@ -313,10 +329,12 @@ void ManhattanStyle::polish(QPalette &pal)
QIcon ManhattanStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const QIcon ManhattanStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
{ {
QIcon icon; QIcon icon;
switch (standardIcon) { switch (standardIcon) {
case QStyle::SP_TitleBarCloseButton: case QStyle::SP_TitleBarCloseButton:
case QStyle::SP_ToolBarHorizontalExtensionButton: case QStyle::SP_ToolBarHorizontalExtensionButton:
return QIcon(standardPixmap(standardIcon, option, widget)); return QIcon(standardPixmap(standardIcon, option, widget));
default: default:
icon = baseStyle()->standardIcon(standardIcon, option, widget); icon = baseStyle()->standardIcon(standardIcon, option, widget);
} }
@ -326,8 +344,9 @@ QIcon ManhattanStyle::standardIconImplementation(StandardPixmap standardIcon, co
QPixmap ManhattanStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, QPixmap ManhattanStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
const QWidget *widget) const const QWidget *widget) const
{ {
if (widget && !panelWidget(widget)) if (widget && !panelWidget(widget)) {
return QProxyStyle::standardPixmap(standardPixmap, opt, widget); return QProxyStyle::standardPixmap(standardPixmap, opt, widget);
}
QPixmap pixmap; QPixmap pixmap;
switch (standardPixmap) { switch (standardPixmap) {
@ -348,15 +367,18 @@ int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const
QStyleHintReturn *returnData) const QStyleHintReturn *returnData) const
{ {
int ret = QProxyStyle::styleHint(hint, option, widget, returnData); int ret = QProxyStyle::styleHint(hint, option, widget, returnData);
switch (hint) { switch (hint) {
// Make project explorer alternate rows all the way // Make project explorer alternate rows all the way
case QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea: case QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea:
if (widget && widget->property("AlternateEmpty").toBool()) if (widget && widget->property("AlternateEmpty").toBool()) {
ret = true; ret = true;
}
break; break;
case QStyle::SH_EtchDisabledText: case QStyle::SH_EtchDisabledText:
if (panelWidget(widget)) if (panelWidget(widget)) {
ret = false; ret = false;
}
break; break;
case QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren: case QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren:
ret = true; ret = true;
@ -370,16 +392,17 @@ int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const QPainter *painter, const QWidget *widget) const
{ {
if (!panelWidget(widget)) if (!panelWidget(widget)) {
return QProxyStyle::drawPrimitive(element, option, painter, widget); return QProxyStyle::drawPrimitive(element, option, painter, widget);
}
bool animating = (option->state & State_Animating); bool animating = (option->state & State_Animating);
int state = option->state; int state = option->state;
QRect rect = option->rect; QRect rect = option->rect;
QRect oldRect; QRect oldRect;
QRect newRect; QRect newRect;
if (widget && (element == PE_PanelButtonTool) && !animating) { if (widget && (element == PE_PanelButtonTool) && !animating) {
QWidget *w = const_cast<QWidget *> (widget); QWidget *w = const_cast<QWidget *> (widget);
int oldState = w->property("_q_stylestate").toInt(); int oldState = w->property("_q_stylestate").toInt();
oldRect = w->property("_q_stylerect").toRect(); oldRect = w->property("_q_stylerect").toRect();
newRect = w->rect(); newRect = w->rect();
@ -387,10 +410,9 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
w->setProperty("_q_stylerect", w->rect()); w->setProperty("_q_stylerect", w->rect());
// Determine the animated transition // Determine the animated transition
bool doTransition = ((state & State_On) != (oldState & State_On) || bool doTransition = ((state & State_On) != (oldState & State_On) ||
(state & State_MouseOver) != (oldState & State_MouseOver)); (state & State_MouseOver) != (oldState & State_MouseOver));
if (oldRect != newRect) if (oldRect != newRect) {
{
doTransition = false; doTransition = false;
d->animator.stopAnimation(widget); d->animator.stopAnimation(widget);
} }
@ -398,9 +420,9 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
if (doTransition) { if (doTransition) {
QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
Animation *anim = d->animator.widgetAnimation(widget); Animation *anim = d->animator.widgetAnimation(widget);
QStyleOption opt = *option; QStyleOption opt = *option;
opt.state = (QStyle::State)oldState; opt.state = (QStyle::State)oldState;
opt.state |= State_Animating; opt.state |= State_Animating;
startImage.fill(0); startImage.fill(0);
Transition *t = new Transition; Transition *t = new Transition;
@ -420,10 +442,11 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
QPainter endPainter(&endImage); QPainter endPainter(&endImage);
drawPrimitive(element, &endOpt, &endPainter, widget); drawPrimitive(element, &endOpt, &endPainter, widget);
t->setEndImage(endImage); t->setEndImage(endImage);
if (oldState & State_MouseOver) if (oldState & State_MouseOver) {
t->setDuration(150); t->setDuration(150);
else } else {
t->setDuration(75); t->setDuration(75);
}
t->setStartTime(QTime::currentTime()); t->setStartTime(QTime::currentTime());
} }
} }
@ -436,160 +459,162 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
QCommonStyle::drawPrimitive(element, option, painter, widget); QCommonStyle::drawPrimitive(element, option, painter, widget);
break; break;
case PE_PanelLineEdit: case PE_PanelLineEdit:
{ {
painter->save(); painter->save();
// Fill the line edit background // Fill the line edit background
QRect filledRect = option->rect.adjusted(1, 1, -1, -1); QRect filledRect = option->rect.adjusted(1, 1, -1, -1);
painter->setBrushOrigin(filledRect.topLeft()); painter->setBrushOrigin(filledRect.topLeft());
painter->fillRect(filledRect, option->palette.base()); painter->fillRect(filledRect, option->palette.base());
if (option->state & State_Enabled) if (option->state & State_Enabled) {
Utils::StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5); Utils::StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5);
else } else {
Utils::StyleHelper::drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5); Utils::StyleHelper::drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5);
if (option->state & State_HasFocus || option->state & State_MouseOver) {
QColor hover = Utils::StyleHelper::baseColor();
if (state & State_HasFocus)
hover.setAlpha(100);
else
hover.setAlpha(50);
painter->setPen(QPen(hover, 1));
painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2));
}
painter->restore();
} }
break;
if (option->state & State_HasFocus || option->state & State_MouseOver) {
QColor hover = Utils::StyleHelper::baseColor();
if (state & State_HasFocus) {
hover.setAlpha(100);
} else {
hover.setAlpha(50);
}
painter->setPen(QPen(hover, 1));
painter->drawRect(option->rect.adjusted(1, 1, -2, -2));
}
painter->restore();
}
break;
case PE_FrameStatusBarItem: case PE_FrameStatusBarItem:
break; break;
case PE_PanelButtonTool: { case PE_PanelButtonTool:
Animation *anim = d->animator.widgetAnimation(widget); {
if (!animating && anim) { Animation *anim = d->animator.widgetAnimation(widget);
anim->paint(painter, option); if (!animating && anim) {
} else { anim->paint(painter, option);
bool pressed = option->state & State_Sunken || option->state & State_On; } else {
QColor shadow(0, 0, 0, 30); bool pressed = option->state & State_Sunken || option->state & State_On;
painter->setPen(shadow); QColor shadow(0, 0, 0, 30);
if (pressed) { painter->setPen(shadow);
QColor shade(0, 0, 0, 40); if (pressed) {
painter->fillRect(rect, shade); QColor shade(0, 0, 0, 40);
painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0)); painter->fillRect(rect, shade);
painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0));
painter->drawLine(rect.topRight(), rect.bottomRight()); painter->drawLine(rect.topLeft(), rect.bottomLeft());
// painter->drawLine(rect.bottomLeft() + QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); painter->drawLine(rect.topRight(), rect.bottomRight());
QColor highlight(255, 255, 255, 30); // painter->drawLine(rect.bottomLeft() + QPoint(1, 0), rect.bottomRight() - QPoint(1, 0));
painter->setPen(highlight); QColor highlight(255, 255, 255, 30);
} painter->setPen(highlight);
else if (option->state & State_Enabled && } else if (option->state & State_Enabled &&
option->state & State_MouseOver) { option->state & State_MouseOver) {
QColor lighter(255, 255, 255, 37); QColor lighter(255, 255, 255, 37);
painter->fillRect(rect, lighter); painter->fillRect(rect, lighter);
} }
if (option->state & State_HasFocus && (option->state & State_KeyboardFocusChange)) { if (option->state & State_HasFocus && (option->state & State_KeyboardFocusChange)) {
QColor highlight = option->palette.highlight().color(); QColor highlight = option->palette.highlight().color();
highlight.setAlphaF(0.4); highlight.setAlphaF(0.4);
painter->setPen(QPen(highlight.lighter(), 1)); painter->setPen(QPen(highlight.lighter(), 1));
highlight.setAlphaF(0.3); highlight.setAlphaF(0.3);
painter->setBrush(highlight); painter->setBrush(highlight);
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
QRectF rect = option->rect; QRectF rect = option->rect;
rect.translate(0.5, 0.5); rect.translate(0.5, 0.5);
painter->drawRoundedRect(rect.adjusted(2, 2, -3, -3), 2, 2); painter->drawRoundedRect(rect.adjusted(2, 2, -3, -3), 2, 2);
} }
}
} }
break; }
break;
case PE_PanelStatusBar: case PE_PanelStatusBar:
{ {
painter->save(); painter->save();
QLinearGradient grad = Utils::StyleHelper::statusBarGradient(rect); QLinearGradient grad = Utils::StyleHelper::statusBarGradient(rect);
painter->fillRect(rect, grad); painter->fillRect(rect, grad);
painter->setPen(QColor(255, 255, 255, 60)); painter->setPen(QColor(255, 255, 255, 60));
painter->drawLine(rect.topLeft() + QPoint(0,1), painter->drawLine(rect.topLeft() + QPoint(0, 1),
rect.topRight()+ QPoint(0,1)); rect.topRight() + QPoint(0, 1));
painter->setPen(Utils::StyleHelper::borderColor().darker(110)); painter->setPen(Utils::StyleHelper::borderColor().darker(110));
painter->drawLine(rect.topLeft(), rect.topRight()); painter->drawLine(rect.topLeft(), rect.topRight());
painter->restore(); painter->restore();
} }
break; break;
case PE_IndicatorToolBarSeparator: case PE_IndicatorToolBarSeparator:
{ {
QColor separatorColor = Utils::StyleHelper::borderColor(); QColor separatorColor = Utils::StyleHelper::borderColor();
separatorColor.setAlpha(100); separatorColor.setAlpha(100);
painter->setPen(separatorColor); painter->setPen(separatorColor);
const int margin = 6; const int margin = 6;
if (option->state & State_Horizontal) { if (option->state & State_Horizontal) {
const int offset = rect.width()/2; const int offset = rect.width() / 2;
painter->drawLine(rect.bottomLeft().x() + offset, painter->drawLine(rect.bottomLeft().x() + offset,
rect.bottomLeft().y() - margin, rect.bottomLeft().y() - margin,
rect.topLeft().x() + offset, rect.topLeft().x() + offset,
rect.topLeft().y() + margin); rect.topLeft().y() + margin);
} else { //Draw vertical separator } else { // Draw vertical separator
const int offset = rect.height()/2; const int offset = rect.height() / 2;
painter->setPen(QPen(option->palette.background().color().darker(110))); painter->setPen(QPen(option->palette.background().color().darker(110)));
painter->drawLine(rect.topLeft().x() + margin , painter->drawLine(rect.topLeft().x() + margin,
rect.topLeft().y() + offset, rect.topLeft().y() + offset,
rect.topRight().x() - margin, rect.topRight().x() - margin,
rect.topRight().y() + offset); rect.topRight().y() + offset);
}
} }
break; }
break;
case PE_IndicatorToolBarHandle: case PE_IndicatorToolBarHandle:
{ {
bool horizontal = option->state & State_Horizontal; bool horizontal = option->state & State_Horizontal;
painter->save(); painter->save();
QPainterPath path; QPainterPath path;
int x = option->rect.x() + (horizontal ? 2 : 6); int x = option->rect.x() + (horizontal ? 2 : 6);
int y = option->rect.y() + (horizontal ? 6 : 2); int y = option->rect.y() + (horizontal ? 6 : 2);
static const int RectHeight = 2; static const int RectHeight = 2;
if (horizontal) { if (horizontal) {
while (y < option->rect.height() - RectHeight - 6) { while (y < option->rect.height() - RectHeight - 6) {
path.moveTo(x, y); path.moveTo(x, y);
path.addRect(x, y, RectHeight, RectHeight); path.addRect(x, y, RectHeight, RectHeight);
y += 6; y += 6;
} }
} else { } else {
while (x < option->rect.width() - RectHeight - 6) { while (x < option->rect.width() - RectHeight - 6) {
path.moveTo(x, y); path.moveTo(x, y);
path.addRect(x, y, RectHeight, RectHeight); path.addRect(x, y, RectHeight, RectHeight);
x += 6; x += 6;
}
} }
painter->setPen(Qt::NoPen);
QColor dark = Utils::StyleHelper::borderColor();
dark.setAlphaF(0.4);
QColor light = Utils::StyleHelper::baseColor();
light.setAlphaF(0.4);
painter->fillPath(path, light);
painter->save();
painter->translate(1, 1);
painter->fillPath(path, dark);
painter->restore();
painter->translate(3, 3);
painter->fillPath(path, light);
painter->translate(1, 1);
painter->fillPath(path, dark);
painter->restore();
} }
break;
painter->setPen(Qt::NoPen);
QColor dark = Utils::StyleHelper::borderColor();
dark.setAlphaF(0.4);
QColor light = Utils::StyleHelper::baseColor();
light.setAlphaF(0.4);
painter->fillPath(path, light);
painter->save();
painter->translate(1, 1);
painter->fillPath(path, dark);
painter->restore();
painter->translate(3, 3);
painter->fillPath(path, light);
painter->translate(1, 1);
painter->fillPath(path, dark);
painter->restore();
}
break;
case PE_IndicatorArrowUp: case PE_IndicatorArrowUp:
case PE_IndicatorArrowDown: case PE_IndicatorArrowDown:
case PE_IndicatorArrowRight: case PE_IndicatorArrowRight:
case PE_IndicatorArrowLeft: case PE_IndicatorArrowLeft:
{ {
Utils::StyleHelper::drawArrow(element, painter, option); Utils::StyleHelper::drawArrow(element, painter, option);
} }
break; break;
default: default:
QProxyStyle::drawPrimitive(element, option, painter, widget); QProxyStyle::drawPrimitive(element, option, painter, widget);
@ -600,8 +625,9 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option, void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const QPainter *painter, const QWidget *widget) const
{ {
if (!panelWidget(widget)) if (!panelWidget(widget)) {
return QProxyStyle::drawControl(element, option, painter, widget); return QProxyStyle::drawControl(element, option, painter, widget);
}
switch (element) { switch (element) {
case CE_Splitter: case CE_Splitter:
@ -612,16 +638,16 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
// Most styles draw a single dark outline. This looks rather ugly when combined with our // Most styles draw a single dark outline. This looks rather ugly when combined with our
// single pixel dark separator so we adjust the first tab to compensate for this // single pixel dark separator so we adjust the first tab to compensate for this
if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) { if (const QStyleOptionTabV3 * tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
QStyleOptionTabV3 adjustedTab = *tab; QStyleOptionTabV3 adjustedTab = *tab;
if (tab->cornerWidgets == QStyleOptionTab::NoCornerWidgets && ( if (tab->cornerWidgets == QStyleOptionTab::NoCornerWidgets && (
tab->position == QStyleOptionTab::Beginning || tab->position == QStyleOptionTab::Beginning ||
tab->position == QStyleOptionTab::OnlyOneTab)) tab->position == QStyleOptionTab::OnlyOneTab)) {
{ if (option->direction == Qt::LeftToRight) {
if (option->direction == Qt::LeftToRight)
adjustedTab.rect = adjustedTab.rect.adjusted(-1, 0, 0, 0); adjustedTab.rect = adjustedTab.rect.adjusted(-1, 0, 0, 0);
else } else {
adjustedTab.rect = adjustedTab.rect.adjusted(0, 0, 1 ,0); adjustedTab.rect = adjustedTab.rect.adjusted(0, 0, 1, 0);
}
} }
QProxyStyle::drawControl(element, &adjustedTab, painter, widget); QProxyStyle::drawControl(element, &adjustedTab, painter, widget);
return; return;
@ -630,13 +656,13 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
case CE_MenuBarItem: case CE_MenuBarItem:
painter->save(); painter->save();
if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { if (const QStyleOptionMenuItem * mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
QColor highlightOutline = Utils::StyleHelper::borderColor().lighter(120); QColor highlightOutline = Utils::StyleHelper::borderColor().lighter(120);
bool act = mbi->state & State_Sunken; bool act = mbi->state & State_Sunken;
bool dis = !(mbi->state & State_Enabled); bool dis = !(mbi->state & State_Enabled);
Utils::StyleHelper::menuGradient(painter, option->rect, option->rect); Utils::StyleHelper::menuGradient(painter, option->rect, option->rect);
QStyleOptionMenuItem item = *mbi; QStyleOptionMenuItem item = *mbi;
item.rect = mbi->rect; item.rect = mbi->rect;
QPalette pal = mbi->palette; QPalette pal = mbi->palette;
pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black); pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black);
item.palette = pal; item.palette = pal;
@ -661,10 +687,11 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
painter->drawPoint(r.topLeft()); painter->drawPoint(r.topLeft());
painter->drawPoint(r.topRight()); painter->drawPoint(r.topRight());
QPalette pal = mbi->palette; QPalette pal = mbi->palette;
uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
if (!styleHint(SH_UnderlineShortcut, mbi, widget)) if (!styleHint(SH_UnderlineShortcut, mbi, widget)) {
alignment |= Qt::TextHideMnemonic; alignment |= Qt::TextHideMnemonic;
}
pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60)); pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60));
drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text); drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text);
pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white); pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white);
@ -675,30 +702,32 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
break; break;
case CE_ComboBoxLabel: case CE_ComboBoxLabel:
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { if (const QStyleOptionComboBox * cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
if (panelWidget(widget)) { if (panelWidget(widget)) {
painter->save(); painter->save();
QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget); QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
QPalette customPal = cb->palette; QPalette customPal = cb->palette;
bool drawIcon = !(widget && widget->property("hideicon").toBool()); bool drawIcon = !(widget && widget->property("hideicon").toBool());
if (!cb->currentIcon.isNull() && drawIcon) { if (!cb->currentIcon.isNull() && drawIcon) {
QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
: QIcon::Disabled; : QIcon::Disabled;
QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
QRect iconRect(editRect); QRect iconRect(editRect);
iconRect.setWidth(cb->iconSize.width() + 4); iconRect.setWidth(cb->iconSize.width() + 4);
iconRect = alignedRect(cb->direction, iconRect = alignedRect(cb->direction,
Qt::AlignLeft | Qt::AlignVCenter, Qt::AlignLeft | Qt::AlignVCenter,
iconRect.size(), editRect); iconRect.size(), editRect);
if (cb->editable) if (cb->editable) {
painter->fillRect(iconRect, customPal.brush(QPalette::Base)); painter->fillRect(iconRect, customPal.brush(QPalette::Base));
}
drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap); drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
if (cb->direction == Qt::RightToLeft) if (cb->direction == Qt::RightToLeft) {
editRect.translate(-4 - cb->iconSize.width(), 0); editRect.translate(-4 - cb->iconSize.width(), 0);
else } else {
editRect.translate(cb->iconSize.width() + 4, 0); editRect.translate(cb->iconSize.width() + 4, 0);
}
// Reserve some space for the down-arrow // Reserve some space for the down-arrow
editRect.adjust(0, 0, -13, 0); editRect.adjust(0, 0, -13, 0);
@ -734,94 +763,101 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
} }
break; break;
case CE_SizeGrip: { case CE_SizeGrip:
painter->save(); {
QColor dark = Qt::white; painter->save();
dark.setAlphaF(0.1); QColor dark = Qt::white;
int x, y, w, h; dark.setAlphaF(0.1);
option->rect.getRect(&x, &y, &w, &h); int x, y, w, h;
int sw = qMin(h, w); option->rect.getRect(&x, &y, &w, &h);
if (h > w) int sw = qMin(h, w);
painter->translate(0, h - w); if (h > w) {
else painter->translate(0, h - w);
painter->translate(w - h, 0); } else {
int sx = x; painter->translate(w - h, 0);
int sy = y; }
int s = 4; int sx = x;
painter->setPen(dark); int sy = y;
if (option->direction == Qt::RightToLeft) { int s = 4;
sx = x + sw; painter->setPen(dark);
for (int i = 0; i < 4; ++i) { if (option->direction == Qt::RightToLeft) {
painter->drawLine(x, sy, sx, sw); sx = x + sw;
sx -= s; for (int i = 0; i < 4; ++i) {
sy += s; painter->drawLine(x, sy, sx, sw);
} sx -= s;
} else { sy += s;
for (int i = 0; i < 4; ++i) { }
painter->drawLine(sx, sw, sw, sy); } else {
sx += s; for (int i = 0; i < 4; ++i) {
sy += s; painter->drawLine(sx, sw, sw, sy);
} sx += s;
sy += s;
} }
painter->restore();
} }
break; painter->restore();
}
break;
case CE_MenuBarEmptyArea: { case CE_MenuBarEmptyArea:
Utils::StyleHelper::menuGradient(painter, option->rect, option->rect); {
painter->save(); Utils::StyleHelper::menuGradient(painter, option->rect, option->rect);
painter->setPen(Utils::StyleHelper::borderColor()); painter->save();
painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); painter->setPen(Utils::StyleHelper::borderColor());
painter->restore(); painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
} painter->restore();
break; }
break;
case CE_ToolBar: case CE_ToolBar:
{ {
QRect rect = option->rect; QRect rect = option->rect;
bool horizontal = option->state & State_Horizontal; bool horizontal = option->state & State_Horizontal;
rect = option->rect; rect = option->rect;
// Map offset for global window gradient // Map offset for global window gradient
QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) - QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
widget->mapToGlobal(option->rect.topLeft()); widget->mapToGlobal(option->rect.topLeft());
QRect gradientSpan; QRect gradientSpan;
if (widget) if (widget) {
gradientSpan = QRect(offset, widget->window()->size()); gradientSpan = QRect(offset, widget->window()->size());
bool drawLightColored = lightColored(widget);
if (horizontal)
Utils::StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
else
Utils::StyleHelper::verticalGradient(painter, gradientSpan, rect, drawLightColored);
if (!drawLightColored)
painter->setPen(Utils::StyleHelper::borderColor());
else
painter->setPen(QColor(0x888888));
if (horizontal) {
// Note: This is a hack to determine if the
// toolbar should draw the top or bottom outline
// (needed for the find toolbar for instance)
QColor lighter(Utils::StyleHelper::sidebarHighlight());
if (drawLightColored)
lighter = QColor(255, 255, 255, 180);
if (widget && widget->property("topBorder").toBool()) {
painter->drawLine(rect.topLeft(), rect.topRight());
painter->setPen(lighter);
painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
} else {
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
painter->setPen(lighter);
painter->drawLine(rect.topLeft(), rect.topRight());
}
} else {
painter->drawLine(rect.topLeft(), rect.bottomLeft());
painter->drawLine(rect.topRight(), rect.bottomRight());
}
} }
break;
bool drawLightColored = lightColored(widget);
if (horizontal) {
Utils::StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
} else {
Utils::StyleHelper::verticalGradient(painter, gradientSpan, rect, drawLightColored);
}
if (!drawLightColored) {
painter->setPen(Utils::StyleHelper::borderColor());
} else {
painter->setPen(QColor(0x888888));
}
if (horizontal) {
// Note: This is a hack to determine if the
// toolbar should draw the top or bottom outline
// (needed for the find toolbar for instance)
QColor lighter(Utils::StyleHelper::sidebarHighlight());
if (drawLightColored) {
lighter = QColor(255, 255, 255, 180);
}
if (widget && widget->property("topBorder").toBool()) {
painter->drawLine(rect.topLeft(), rect.topRight());
painter->setPen(lighter);
painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1));
} else {
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
painter->setPen(lighter);
painter->drawLine(rect.topLeft(), rect.topRight());
}
} else {
painter->drawLine(rect.topLeft(), rect.bottomLeft());
painter->drawLine(rect.topRight(), rect.bottomRight());
}
}
break;
default: default:
QProxyStyle::drawControl(element, option, painter, widget); QProxyStyle::drawControl(element, option, painter, widget);
@ -832,41 +868,46 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
QPainter *painter, const QWidget *widget) const QPainter *painter, const QWidget *widget) const
{ {
if (!panelWidget(widget)) if (!panelWidget(widget)) {
return QProxyStyle::drawComplexControl(control, option, painter, widget); return QProxyStyle::drawComplexControl(control, option, painter, widget);
}
QRect rect = option->rect; QRect rect = option->rect;
switch (control) { switch (control) {
case CC_ToolButton: case CC_ToolButton:
if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { if (const QStyleOptionToolButton * toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
bool reverse = option->direction == Qt::RightToLeft; bool reverse = option->direction == Qt::RightToLeft;
bool drawborder = (widget && widget->property("showborder").toBool()); bool drawborder = (widget && widget->property("showborder").toBool());
if (drawborder) if (drawborder) {
drawButtonSeparator(painter, rect, reverse); drawButtonSeparator(painter, rect, reverse);
}
QRect button, menuarea; QRect button, menuarea;
button = subControlRect(control, toolbutton, SC_ToolButton, widget); button = subControlRect(control, toolbutton, SC_ToolButton, widget);
menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget); menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);
State bflags = toolbutton->state; State bflags = toolbutton->state;
if (bflags & State_AutoRaise) { if (bflags & State_AutoRaise) {
if (!(bflags & State_MouseOver)) if (!(bflags & State_MouseOver)) {
bflags &= ~State_Raised; bflags &= ~State_Raised;
}
} }
State mflags = bflags; State mflags = bflags;
if (toolbutton->state & State_Sunken) { if (toolbutton->state & State_Sunken) {
if (toolbutton->activeSubControls & SC_ToolButton) if (toolbutton->activeSubControls & SC_ToolButton) {
bflags |= State_Sunken; bflags |= State_Sunken;
if (toolbutton->activeSubControls & SC_ToolButtonMenu) }
if (toolbutton->activeSubControls & SC_ToolButtonMenu) {
mflags |= State_Sunken; mflags |= State_Sunken;
}
} }
QStyleOption tool(0); QStyleOption tool(0);
tool.palette = toolbutton->palette; tool.palette = toolbutton->palette;
if (toolbutton->subControls & SC_ToolButton) { if (toolbutton->subControls & SC_ToolButton) {
tool.rect = button; tool.rect = button;
tool.state = bflags; tool.state = bflags;
drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
} }
@ -875,13 +916,13 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
label.palette = panelPalette(option->palette, lightColored(widget)); label.palette = panelPalette(option->palette, lightColored(widget));
int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
label.rect = button.adjusted(fw, fw, -fw, -fw); label.rect = button.adjusted(fw, fw, -fw, -fw);
drawControl(CE_ToolButtonLabel, &label, painter, widget); drawControl(CE_ToolButtonLabel, &label, painter, widget);
if (toolbutton->subControls & SC_ToolButtonMenu) { if (toolbutton->subControls & SC_ToolButtonMenu) {
tool.state = mflags; tool.state = mflags;
tool.rect = menuarea.adjusted(1, 1, -1, -1); tool.rect = menuarea.adjusted(1, 1, -1, -1);
if (mflags & (State_Sunken | State_On | State_Raised)) { if (mflags & (State_Sunken | State_On | State_Raised)) {
painter->setPen(Qt::gray); painter->setPen(Qt::gray);
painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft()); painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft());
@ -901,53 +942,59 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1); QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1);
QStyleOptionToolButton newBtn = *toolbutton; QStyleOptionToolButton newBtn = *toolbutton;
newBtn.palette = panelPalette(option->palette); newBtn.palette = panelPalette(option->palette);
newBtn.rect = QRect(ir.right() - arrowSize - 1, newBtn.rect = QRect(ir.right() - arrowSize - 1,
ir.height() - arrowSize - 2, arrowSize, arrowSize); ir.height() - arrowSize - 2, arrowSize, arrowSize);
drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget); drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
} }
} }
break; break;
case CC_ComboBox: case CC_ComboBox:
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { if (const QStyleOptionComboBox * cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
painter->save(); painter->save();
bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull(); bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull();
bool reverse = option->direction == Qt::RightToLeft; bool reverse = option->direction == Qt::RightToLeft;
bool drawborder = !(widget && widget->property("hideborder").toBool()); bool drawborder = !(widget && widget->property("hideborder").toBool());
bool alignarrow = !(widget && widget->property("alignarrow").toBool()); bool alignarrow = !(widget && widget->property("alignarrow").toBool());
if (drawborder) if (drawborder) {
drawButtonSeparator(painter, rect, reverse); drawButtonSeparator(painter, rect, reverse);
}
QStyleOption toolbutton = *option; QStyleOption toolbutton = *option;
if (isEmpty) if (isEmpty) {
toolbutton.state &= ~(State_Enabled | State_Sunken); toolbutton.state &= ~(State_Enabled | State_Sunken);
}
painter->save(); painter->save();
if (drawborder) if (drawborder) {
painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0)); painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0));
}
drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget); drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget);
painter->restore(); painter->restore();
// Draw arrow // Draw arrow
int menuButtonWidth = 12; int menuButtonWidth = 12;
int left = !reverse ? rect.right() - menuButtonWidth : rect.left(); int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
int right = !reverse ? rect.right() : rect.left() + menuButtonWidth; int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9); QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9);
if (!alignarrow) { if (!alignarrow) {
int labelwidth = option->fontMetrics.width(cb->currentText); int labelwidth = option->fontMetrics.width(cb->currentText);
if (reverse) if (reverse) {
arrowRect.moveLeft(qMax(rect.width() - labelwidth - menuButtonWidth - 2, 4)); arrowRect.moveLeft(qMax(rect.width() - labelwidth - menuButtonWidth - 2, 4));
else } else {
arrowRect.moveLeft(qMin(labelwidth + menuButtonWidth - 2, rect.width() - menuButtonWidth - 4)); arrowRect.moveLeft(qMin(labelwidth + menuButtonWidth - 2, rect.width() - menuButtonWidth - 4));
}
} }
if (option->state & State_On) if (option->state & State_On) {
arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget), arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget),
QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget)); QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget));
}
QStyleOption arrowOpt = *option; QStyleOption arrowOpt = *option;
arrowOpt.rect = arrowRect; arrowOpt.rect = arrowRect;
if (isEmpty) if (isEmpty) {
arrowOpt.state &= ~(State_Enabled | State_Sunken); arrowOpt.state &= ~(State_Enabled | State_Sunken);
}
if (styleHint(SH_ComboBox_Popup, option, widget)) { if (styleHint(SH_ComboBox_Popup, option, widget)) {
arrowOpt.rect.translate(0, -3); arrowOpt.rect.translate(0, -3);
@ -971,6 +1018,7 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
void ManhattanStyle::drawButtonSeparator(QPainter *painter, const QRect &rect, bool reverse) const void ManhattanStyle::drawButtonSeparator(QPainter *painter, const QRect &rect, bool reverse) const
{ {
QLinearGradient grad(rect.topRight(), rect.bottomRight()); QLinearGradient grad(rect.topRight(), rect.bottomRight());
grad.setColorAt(0, QColor(255, 255, 255, 20)); grad.setColorAt(0, QColor(255, 255, 255, 20));
grad.setColorAt(0.4, QColor(255, 255, 255, 60)); grad.setColorAt(0.4, QColor(255, 255, 255, 60));
grad.setColorAt(0.7, QColor(255, 255, 255, 50)); grad.setColorAt(0.7, QColor(255, 255, 255, 50));
@ -982,8 +1030,9 @@ void ManhattanStyle::drawButtonSeparator(QPainter *painter, const QRect &rect, b
grad.setColorAt(0.7, QColor(0, 0, 0, 70)); grad.setColorAt(0.7, QColor(0, 0, 0, 70));
grad.setColorAt(1, QColor(0, 0, 0, 40)); grad.setColorAt(1, QColor(0, 0, 0, 40));
painter->setPen(QPen(grad, 0)); painter->setPen(QPen(grad, 0));
if (!reverse) if (!reverse) {
painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0)); painter->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0));
else } else {
painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topLeft(), rect.bottomLeft());
} }
}

View File

@ -35,8 +35,7 @@
class ManhattanStylePrivate; class ManhattanStylePrivate;
class CORE_EXPORT ManhattanStyle : public QProxyStyle class CORE_EXPORT ManhattanStyle : public QProxyStyle {
{
Q_OBJECT Q_OBJECT
public: public:

View File

@ -39,13 +39,11 @@ using namespace Core::Internal;
const int WorkspaceSettings::MAX_WORKSPACES = 10; const int WorkspaceSettings::MAX_WORKSPACES = 10;
WorkspaceSettings::WorkspaceSettings(QObject *parent) : WorkspaceSettings::WorkspaceSettings(QObject *parent) :
IOptionsPage(parent) IOptionsPage(parent)
{ {}
}
WorkspaceSettings::~WorkspaceSettings() WorkspaceSettings::~WorkspaceSettings()
{ {}
}
// IOptionsPage // IOptionsPage
@ -121,8 +119,8 @@ void WorkspaceSettings::readSettings(QSettings *qs)
m_iconNames.append(iconName); m_iconNames.append(iconName);
m_modeNames.append(QString("Mode") + QString::number(i)); m_modeNames.append(QString("Mode") + QString::number(i));
} }
m_tabBarPlacementIndex = qs->value(QLatin1String("TabBarPlacementIndex"), 1).toInt(); // 1 == "Bottom" m_tabBarPlacementIndex = qs->value(QLatin1String("TabBarPlacementIndex"), 1).toInt(); // 1 == "Bottom"
m_allowTabBarMovement = qs->value(QLatin1String("AllowTabBarMovement"), false).toBool(); m_allowTabBarMovement = qs->value(QLatin1String("AllowTabBarMovement"), false).toBool();
m_restoreSelectedOnStartup = qs->value(QLatin1String("RestoreSelectedOnStartup"), false).toBool(); m_restoreSelectedOnStartup = qs->value(QLatin1String("RestoreSelectedOnStartup"), false).toBool();
qs->endGroup(); qs->endGroup();
@ -169,8 +167,8 @@ void WorkspaceSettings::apply()
modeManager->updateModeNameIcon(mode, QIcon(iconName(i)), name(i)); modeManager->updateModeNameIcon(mode, QIcon(iconName(i)), name(i));
} }
} }
m_tabBarPlacementIndex = m_page->comboBoxTabBarPlacement->currentIndex(); m_tabBarPlacementIndex = m_page->comboBoxTabBarPlacement->currentIndex();
m_allowTabBarMovement = m_page->checkBoxAllowTabMovement->isChecked(); m_allowTabBarMovement = m_page->checkBoxAllowTabMovement->isChecked();
m_restoreSelectedOnStartup = m_page->checkBoxRestoreSelectedOnStartup->isChecked(); m_restoreSelectedOnStartup = m_page->checkBoxRestoreSelectedOnStartup->isChecked();
QTabWidget::TabPosition pos = m_tabBarPlacementIndex == 0 ? QTabWidget::North : QTabWidget::South; QTabWidget::TabPosition pos = m_tabBarPlacementIndex == 0 ? QTabWidget::North : QTabWidget::South;