summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-04-27 12:55:43 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2010-04-27 14:11:57 +0200
commitd45da3f105cc1480ebb686b23ecf57b7bb72c4f2 (patch)
tree7f6376efb30b580646ac81e5237730741022eaf3
parentdf7148b7a81a242f0399b3517ace87e080c298dc (diff)
Merge Manhattan style changes from Qt Creator.
-rw-r--r--library/remotecontrolwidget.cpp4
-rw-r--r--library/remotecontrolwidget.h12
-rw-r--r--library/style/fancylineedit.cpp279
-rw-r--r--library/style/fancylineedit.h53
-rw-r--r--library/style/filterlineedit.cpp17
-rw-r--r--library/style/filterlineedit.h4
-rw-r--r--library/style/manhattanstyle.cpp608
-rw-r--r--library/style/manhattanstyle.h15
-rw-r--r--library/style/styleanimator.h6
-rw-r--r--library/style/styledbar.cpp2
-rw-r--r--library/style/styledbar.h6
-rw-r--r--library/style/stylehelper.cpp240
-rw-r--r--library/style/stylehelper.h26
-rw-r--r--library/toolbox.cpp2
-rw-r--r--library/toolbox.h6
15 files changed, 693 insertions, 587 deletions
diff --git a/library/remotecontrolwidget.cpp b/library/remotecontrolwidget.cpp
index 7831a7f..4f16f61 100644
--- a/library/remotecontrolwidget.cpp
+++ b/library/remotecontrolwidget.cpp
@@ -49,6 +49,8 @@
#include <QtGui/QBoxLayout>
#include <QtGui/QLabel>
+using namespace Utils;
+
RemoteControlWidget::RemoteControlWidget(QWidget *parent)
: QWidget(parent)
{
@@ -88,7 +90,7 @@ RemoteControlWidget::~RemoteControlWidget()
void RemoteControlWidget::changeFilters()
{
- mToolBox->changeFilters(mFilterLineEdit->typedText());
+ mToolBox->changeFilters(mFilterLineEdit->text());
}
void RemoteControlWidget::addSimulateSubPage(ToolBoxPage *page)
diff --git a/library/remotecontrolwidget.h b/library/remotecontrolwidget.h
index 61af995..7e0b617 100644
--- a/library/remotecontrolwidget.h
+++ b/library/remotecontrolwidget.h
@@ -35,10 +35,8 @@
#include <QtGui/QWidget>
class OptionsItem;
-class FilterLineEdit;
class ToolBox;
class ToolBoxPage;
-class StyledBar;
class ManhattanStyle;
class QToolButton;
class QFrame;
@@ -46,6 +44,10 @@ class QLabel;
class QLayout;
class QVBoxLayout;
class QHBoxLayout;
+namespace Utils {
+ class StyledBar;
+ class FilterLineEdit;
+}
class REMOTECONTROLWIDGETSHARED_EXPORT PageWidget: public QWidget
{
@@ -72,7 +74,7 @@ signals:
void advancedButtonClicked() const;
private:
- StyledBar *mHeader;
+ Utils::StyledBar *mHeader;
QHBoxLayout *mHeaderLayout;
QLabel *mHeaderLabel;
QToolButton *mHeaderButton;
@@ -100,11 +102,11 @@ private slots:
void changeFilters();
private:
- StyledBar *initializeMenuBar();
+ Utils::StyledBar *initializeMenuBar();
private:
ToolBox *mToolBox;
- FilterLineEdit *mFilterLineEdit;
+ Utils::FilterLineEdit *mFilterLineEdit;
QLayout *mMenuLayout;
QVBoxLayout *mMainLayout;
diff --git a/library/style/fancylineedit.cpp b/library/style/fancylineedit.cpp
index 384dbd0..21cf49d 100644
--- a/library/style/fancylineedit.cpp
+++ b/library/style/fancylineedit.cpp
@@ -36,29 +36,20 @@
#include <QtGui/QMenu>
#include <QtGui/QMouseEvent>
#include <QtGui/QLabel>
+#include <QtGui/QAbstractButton>
+#include <QtGui/QPainter>
+#include <QtGui/QStyle>
+#include <QtCore/QPropertyAnimation>
-enum { margin = 6 };
-static inline QString sideToStyleSheetString(FancyLineEdit::Side side)
-{
- return side == FancyLineEdit::Left ? QLatin1String("left") : QLatin1String("right");
-}
+enum { margin = 6 };
-// Format style sheet for the label containing the pixmap. It has a margin on
-// the outer side of the whole FancyLineEdit.
-static QString labelStyleSheet(FancyLineEdit::Side side)
-{
- QString rc = QLatin1String("QLabel { margin-");
- rc += sideToStyleSheetString(side);
- rc += QLatin1String(": ");
- rc += QString::number(margin);
- rc += QLatin1Char('}');
- return rc;
-}
+#define ICONBUTTON_SIZE 18
+#define FADE_TIME 160
-// --------- FancyLineEditPrivate as QObject with label
-// event filter
+namespace Utils {
+// --------- FancyLineEditPrivate
class FancyLineEditPrivate : public QObject {
public:
explicit FancyLineEditPrivate(FancyLineEdit *parent);
@@ -71,48 +62,35 @@ public:
FancyLineEdit *m_lineEdit;
QPixmap m_pixmap;
QMenu *m_menu;
- QLabel *m_menuLabel;
FancyLineEdit::Side m_side;
bool m_useLayoutDirection;
bool m_menuTabFocusTrigger;
- QString m_hintText;
- bool m_showingHintText;
+ bool m_autoHideIcon;
+ IconButton *m_iconbutton;
};
FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) :
QObject(parent),
- m_leftLabelStyleSheet(labelStyleSheet(FancyLineEdit::Left)),
- m_rightLabelStyleSheet(labelStyleSheet(FancyLineEdit::Right)),
m_lineEdit(parent),
m_menu(0),
- m_menuLabel(0),
m_side(FancyLineEdit::Left),
m_useLayoutDirection(false),
m_menuTabFocusTrigger(false),
- m_showingHintText(false)
+ m_autoHideIcon(false),
+ m_iconbutton(new IconButton(parent))
{
}
bool FancyLineEditPrivate::eventFilter(QObject *obj, QEvent *event)
{
- if (obj != m_menuLabel)
+ if (obj != m_iconbutton)
return QObject::eventFilter(obj, event);
-
switch (event->type()) {
- case QEvent::MouseButtonPress: {
- const QMouseEvent *me = static_cast<QMouseEvent *>(event);
- if (m_menu) {
- m_menu->exec(me->globalPos());
- } else {
- emit m_lineEdit->buttonClicked();
- }
- return true;
- }
case QEvent::FocusIn:
if (m_menuTabFocusTrigger && m_menu) {
m_lineEdit->setFocus();
- m_menu->exec(m_menuLabel->mapToGlobal(m_menuLabel->rect().center()));
+ m_menu->exec(m_iconbutton->mapToGlobal(m_iconbutton->rect().center()));
return true;
}
default:
@@ -121,95 +99,105 @@ bool FancyLineEditPrivate::eventFilter(QObject *obj, QEvent *event)
return QObject::eventFilter(obj, event);
}
+
// --------- FancyLineEdit
FancyLineEdit::FancyLineEdit(QWidget *parent) :
QLineEdit(parent),
m_d(new FancyLineEditPrivate(this))
{
- m_d->m_menuLabel = new QLabel(this);
- m_d->m_menuLabel->installEventFilter(m_d);
- updateMenuLabel();
- showHintText();
-}
-
-FancyLineEdit::~FancyLineEdit()
-{
+ // KDE has custom icons for this. Notice that icon namings are counter intuitive
+ // If these icons are not avaiable we use the freedesktop standard name before
+ // falling back to a bundled resource
+ QIcon icon = QIcon::fromTheme(layoutDirection() == Qt::LeftToRight ?
+ QLatin1String("edit-clear-locationbar-rtl") :
+ QLatin1String("edit-clear-locationbar-ltr"),
+ QIcon::fromTheme("edit-clear", QIcon(QLatin1String(":/core/images/editclear.png"))));
+
+ m_d->m_iconbutton->installEventFilter(m_d);
+ m_d->m_iconbutton->setIcon(icon);
+
+ ensurePolished();
+ setSide(Left);
+
+ connect(this, SIGNAL(textChanged(QString)), this, SLOT(checkButton(QString)));
+ connect(m_d->m_iconbutton, SIGNAL(clicked()), this, SLOT(iconClicked()));
}
-// Position the menu label left or right according to size.
-// Called when switching side and from resizeEvent.
-void FancyLineEdit::positionMenuLabel()
+void FancyLineEdit::checkButton(const QString &text)
{
- switch (side()) {
- case Left:
- m_d->m_menuLabel->setGeometry(0, 0, m_d->m_pixmap.width()+margin, height());
- break;
- case Right:
- m_d->m_menuLabel->setGeometry(width() - m_d->m_pixmap.width() - margin, 0,
- m_d->m_pixmap.width()+margin, height());
- break;
+ if (autoHideIcon()) {
+ static QString oldtext;
+ if (oldtext.isEmpty() || text.isEmpty())
+ m_d->m_iconbutton->animateShow(!text.isEmpty());
+ oldtext = text;
}
}
-void FancyLineEdit::updateStyleSheet(Side side)
+FancyLineEdit::~FancyLineEdit()
{
- // Udate the LineEdit style sheet. Make room for the label on the
- // respective side and set color according to whether we are showing the
- // hint text
- QString sheet = QLatin1String("QLineEdit{ padding-");
- sheet += sideToStyleSheetString(side);
- sheet += QLatin1String(": ");
- sheet += QString::number(m_d->m_pixmap.width() + margin);
- sheet += QLatin1Char(';');
- if (m_d->m_showingHintText)
- sheet += QLatin1String(" color: #BBBBBB;");
- // Fix the stylesheet's clearing the size hint.
- sheet += QLatin1String(" height: ");
- sheet += QString::number(sizeHint().height());
- sheet += QLatin1Char('}');
- setStyleSheet(sheet);
}
-void FancyLineEdit::updateMenuLabel()
+void FancyLineEdit::setSide(Side side)
{
- m_d->m_menuLabel->setPixmap(m_d->m_pixmap);
- const Side s = side();
- switch (s) {
- case Left:
- m_d->m_menuLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
- m_d->m_menuLabel->setStyleSheet(m_d->m_leftLabelStyleSheet);
- break;
- case Right:
- m_d->m_menuLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
- m_d->m_menuLabel->setStyleSheet(m_d->m_rightLabelStyleSheet);
- break;
+ m_d->m_side = side;
+
+ Side iconpos = side;
+ if (layoutDirection() == Qt::RightToLeft)
+ iconpos = (side == Left ? Right : Left);
+
+ // Make room for icon
+
+ // Let the style determine minimum height for our widget
+ QSize size(ICONBUTTON_SIZE + 6, ICONBUTTON_SIZE + 2);
+
+ // Note KDE does not reserve space for the highlight color
+ if (style()->inherits("OxygenStyle")) {
+ size = size.expandedTo(QSize(24, 0));
}
- updateStyleSheet(s);
- positionMenuLabel();
+
+ QMargins margins;
+ if (iconpos == Right)
+ margins.setRight(size.width());
+ else
+ margins.setLeft(size.width());
+
+ setTextMargins(margins);
}
-void FancyLineEdit::setSide(Side side)
+void FancyLineEdit::iconClicked()
{
- m_d->m_side = side;
- updateMenuLabel();
+ if (m_d->m_menu) {
+ m_d->m_menu->exec(QCursor::pos());
+ } else {
+ emit buttonClicked();
+ }
}
FancyLineEdit::Side FancyLineEdit::side() const
{
- if (m_d->m_useLayoutDirection)
- return qApp->layoutDirection() == Qt::LeftToRight ? Left : Right;
return m_d->m_side;
}
void FancyLineEdit::resizeEvent(QResizeEvent *)
{
- positionMenuLabel();
+ QRect contentRect = rect();
+ Side iconpos = m_d->m_side;
+ if (layoutDirection() == Qt::RightToLeft)
+ iconpos = (iconpos == Left ? Right : Left);
+
+ if (iconpos == FancyLineEdit::Right) {
+ const int iconoffset = textMargins().right() + 4;
+ m_d->m_iconbutton->setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0));
+ } else {
+ const int iconoffset = textMargins().left() + 4;
+ m_d->m_iconbutton->setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0));
+ }
}
void FancyLineEdit::setPixmap(const QPixmap &pixmap)
{
- m_d->m_pixmap = pixmap;
- updateMenuLabel();
+ m_d->m_iconbutton->setIcon(pixmap);
+ updateGeometry();
}
QPixmap FancyLineEdit::pixmap() const
@@ -220,28 +208,14 @@ QPixmap FancyLineEdit::pixmap() const
void FancyLineEdit::setMenu(QMenu *menu)
{
m_d->m_menu = menu;
-}
+ m_d->m_iconbutton->setIconOpacity(1.0);
+ }
QMenu *FancyLineEdit::menu() const
{
return m_d->m_menu;
}
-bool FancyLineEdit::useLayoutDirection() const
-{
- return m_d->m_useLayoutDirection;
-}
-
-void FancyLineEdit::setUseLayoutDirection(bool v)
-{
- m_d->m_useLayoutDirection = v;
-}
-
-bool FancyLineEdit::isSideStored() const
-{
- return !m_d->m_useLayoutDirection;
-}
-
bool FancyLineEdit::hasMenuTabFocusTrigger() const
{
return m_d->m_menuTabFocusTrigger;
@@ -253,63 +227,74 @@ void FancyLineEdit::setMenuTabFocusTrigger(bool v)
return;
m_d->m_menuTabFocusTrigger = v;
- m_d->m_menuLabel->setFocusPolicy(v ? Qt::TabFocus : Qt::NoFocus);
+ m_d->m_iconbutton->setFocusPolicy(v ? Qt::TabFocus : Qt::NoFocus);
}
-QString FancyLineEdit::hintText() const
+bool FancyLineEdit::autoHideIcon() const
{
- return m_d->m_hintText;
+ return m_d->m_autoHideIcon;
}
-void FancyLineEdit::setHintText(const QString &ht)
+void FancyLineEdit::setAutoHideIcon(bool h)
{
- // Updating magic to make the property work in Designer.
- if (ht == m_d->m_hintText)
- return;
- hideHintText();
- m_d->m_hintText = ht;
- if (!hasFocus() && !ht.isEmpty())
- showHintText();
+ m_d->m_autoHideIcon = h;
+ if (h)
+ m_d->m_iconbutton->setIconOpacity(text().isEmpty() ? 0.0 : 1.0);
+ else
+ m_d->m_iconbutton->setIconOpacity(1.0);
}
-void FancyLineEdit::showHintText()
+void FancyLineEdit::setButtonToolTip(const QString &tip)
{
- if (!m_d->m_showingHintText && text().isEmpty() && !m_d->m_hintText.isEmpty()) {
- m_d->m_showingHintText = true;
- setText(m_d->m_hintText);
- updateStyleSheet(side());
- }
+ m_d->m_iconbutton->setToolTip(tip);
}
-void FancyLineEdit::hideHintText()
+void FancyLineEdit::setButtonFocusPolicy(Qt::FocusPolicy policy)
{
- if (m_d->m_showingHintText && !m_d->m_hintText.isEmpty()) {
- m_d->m_showingHintText = false;
- setText(QString());
- updateStyleSheet(side());
- }
+ m_d->m_iconbutton->setFocusPolicy(policy);
}
-void FancyLineEdit::focusInEvent(QFocusEvent *e)
-{
- hideHintText();
- QLineEdit::focusInEvent(e);
-}
+// IconButton - helper class to represent a clickable icon
-void FancyLineEdit::focusOutEvent(QFocusEvent *e)
+IconButton::IconButton(QWidget *parent)
+ : QAbstractButton(parent)
{
- // Focus out: Switch to displaying the hint text unless
- // there is user input
- showHintText();
- QLineEdit::focusOutEvent(e);
+ setCursor(Qt::ArrowCursor);
+ setFocusPolicy(Qt::NoFocus);
}
-bool FancyLineEdit::isShowingHintText() const
+void IconButton::paintEvent(QPaintEvent *)
{
- return m_d->m_showingHintText;
+ QPainter painter(this);
+ // Note isDown should really use the active state but in most styles
+ // this has no proper feedback
+ QIcon::Mode state = QIcon::Disabled;
+ if (isEnabled())
+ state = isDown() ? QIcon::Selected : QIcon::Normal;
+ QPixmap iconpixmap = icon().pixmap(QSize(ICONBUTTON_SIZE, ICONBUTTON_SIZE),
+ state, QIcon::Off);
+ QRect pixmapRect = QRect(0, 0, iconpixmap.width(), iconpixmap.height());
+ pixmapRect.moveCenter(rect().translated(0,-1).center());
+
+ if (static_cast<FancyLineEdit*>(parentWidget())->autoHideIcon())
+ painter.setOpacity(m_iconOpacity);
+
+ painter.drawPixmap(pixmapRect, iconpixmap);
}
-QString FancyLineEdit::typedText() const
+void IconButton::animateShow(bool visible)
{
- return m_d->m_showingHintText ? QString() : text();
+ if (visible) {
+ QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity");
+ animation->setDuration(FADE_TIME);
+ animation->setEndValue(1.0);
+ animation->start(QAbstractAnimation::DeleteWhenStopped);
+ } else {
+ QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity");
+ animation->setDuration(FADE_TIME);
+ animation->setEndValue(0.0);
+ animation->start(QAbstractAnimation::DeleteWhenStopped);
+ }
}
+
+} // namespace Utils
diff --git a/library/style/fancylineedit.h b/library/style/fancylineedit.h
index 2e469c9..6913874 100644
--- a/library/style/fancylineedit.h
+++ b/library/style/fancylineedit.h
@@ -31,9 +31,29 @@
#define FANCYLINEEDIT_H
#include <QtGui/QLineEdit>
+#include <QtGui/QPaintEvent>
+#include <QtGui/QAbstractButton>
+
+namespace Utils {
class FancyLineEditPrivate;
+class IconButton: public QAbstractButton
+{
+ Q_OBJECT
+ Q_PROPERTY(float iconOpacity READ iconOpacity WRITE setIconOpacity)
+public:
+ IconButton(QWidget *parent = 0);
+ void paintEvent(QPaintEvent *event);
+ float iconOpacity() { return m_iconOpacity; }
+ void setIconOpacity(float value) { m_iconOpacity = value; update(); }
+ void animateShow(bool visible);
+
+private:
+ float m_iconOpacity;
+};
+
+
/* A line edit with an embedded pixmap on one side that is connected to
* a menu. Additionally, it can display a grayed hintText (like "Type Here to")
* when not focused and empty. When connecting to the changed signals and
@@ -47,10 +67,9 @@ class FancyLineEdit : public QLineEdit
Q_OBJECT
Q_ENUMS(Side)
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap DESIGNABLE true)
- Q_PROPERTY(Side side READ side WRITE setSide DESIGNABLE isSideStored STORED isSideStored)
- Q_PROPERTY(bool useLayoutDirection READ useLayoutDirection WRITE setUseLayoutDirection DESIGNABLE true)
+ Q_PROPERTY(Side side READ side WRITE setSide DESIGNABLE true)
Q_PROPERTY(bool menuTabFocusTrigger READ hasMenuTabFocusTrigger WRITE setMenuTabFocusTrigger DESIGNABLE true)
- Q_PROPERTY(QString hintText READ hintText WRITE setHintText DESIGNABLE true)
+ Q_PROPERTY(bool autoHideIcon READ autoHideIcon WRITE setAutoHideIcon DESIGNABLE true)
public:
enum Side {Left, Right};
@@ -66,43 +85,35 @@ public:
void setSide(Side side);
Side side() const;
- bool useLayoutDirection() const;
- void setUseLayoutDirection(bool v);
+ void setButtonToolTip(const QString &);
+ void setButtonFocusPolicy(Qt::FocusPolicy policy);
// Set whether tabbing in will trigger the menu.
bool hasMenuTabFocusTrigger() const;
void setMenuTabFocusTrigger(bool v);
- // Hint text that is displayed when no focus is set.
- QString hintText() const;
-
- bool isShowingHintText() const;
-
- // Convenience for accessing the text that returns "" in case of isShowingHintText().
- QString typedText() const;
+ // Set if icon should be hidden when text is empty
+ bool autoHideIcon() const;
+ void setAutoHideIcon(bool h);
signals:
void buttonClicked();
public slots:
void setPixmap(const QPixmap &pixmap);
- void setHintText(const QString &ht);
- void showHintText();
- void hideHintText();
+ void checkButton(const QString &);
+ void iconClicked();
protected:
virtual void resizeEvent(QResizeEvent *e);
- virtual void focusInEvent(QFocusEvent *e);
- virtual void focusOutEvent(QFocusEvent *e);
private:
- friend class FancyLineEditPrivate;
+ friend class Utils::FancyLineEditPrivate;
bool isSideStored() const;
- void updateMenuLabel();
- void positionMenuLabel();
- void updateStyleSheet(Side side);
FancyLineEditPrivate *m_d;
};
+} // namespace Utils
+
#endif // FANCYLINEEDIT_H
diff --git a/library/style/filterlineedit.cpp b/library/style/filterlineedit.cpp
index 7112375..ceee167 100644
--- a/library/style/filterlineedit.cpp
+++ b/library/style/filterlineedit.cpp
@@ -29,23 +29,28 @@
#include "filterlineedit.h"
+namespace Utils {
+
FilterLineEdit::FilterLineEdit(QWidget *parent) :
FancyLineEdit(parent),
- m_lastFilterText(typedText())
+ m_lastFilterText(text())
{
- setSide(FancyLineEdit::Right);
- setPixmap(QPixmap(QLatin1String(":/style/images/reset.png")));
- setHintText(tr("Type to filter"));
-
+ setSide(Utils::FancyLineEdit::Right);
+ setPlaceholderText(tr("Filter"));
+ setButtonToolTip(tr("Clear text"));
+ setAutoHideIcon(true);
connect(this, SIGNAL(buttonClicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged()));
}
void FilterLineEdit::slotTextChanged()
{
- const QString newlyTypedText = typedText();
+ const QString newlyTypedText = text();
if (newlyTypedText != m_lastFilterText) {
m_lastFilterText = newlyTypedText;
emit filterChanged(m_lastFilterText);
}
}
+
+
+} // namespace Utils
diff --git a/library/style/filterlineedit.h b/library/style/filterlineedit.h
index f1653e6..bb8ce36 100644
--- a/library/style/filterlineedit.h
+++ b/library/style/filterlineedit.h
@@ -32,6 +32,8 @@
#include "fancylineedit.h"
+namespace Utils {
+
/* A fancy line edit customized for filtering purposes with a clear button. */
class FilterLineEdit : public FancyLineEdit
@@ -50,4 +52,6 @@ private:
QString m_lastFilterText;
};
+} // namespace Utils
+
#endif // FILTERLINEEDIT_H
diff --git a/library/style/manhattanstyle.cpp b/library/style/manhattanstyle.cpp
index 6823437..b304b79 100644
--- a/library/style/manhattanstyle.cpp
+++ b/library/style/manhattanstyle.cpp
@@ -36,6 +36,8 @@
#include "qtcassert.h"
#include "stylehelper.h"
+//#include <utils/fancymainwindow.h>
+
#include <QtGui/QApplication>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
@@ -55,7 +57,9 @@
#include <QtGui/QStyleFactory>
#include <QtGui/QStyleOption>
#include <QtGui/QToolBar>
+#include <QtGui/QTreeView>
#include <QtGui/QToolButton>
+#include <QtGui/QAbstractItemView>
// We define a currently unused state for indicating animations
#define State_Animating 0x00000040
@@ -79,18 +83,23 @@ bool panelWidget(const QWidget *widget)
if (!widget)
return false;
- // Don't style dialogs or explicitly ignored widgets
+ // Do not style dialogs or explicitly ignored widgets
if (qobject_cast<const QDialog *>(widget->window()))
return false;
+// if (qobject_cast<const Utils::FancyMainWindow *>(widget))
+// return true;
+
+ if (qobject_cast<const QTabBar *>(widget))
+ return styleEnabled(widget);
+
const QWidget *p = widget;
while (p) {
if (qobject_cast<const QToolBar *>(p) ||
qobject_cast<const QStatusBar *>(p) ||
- qobject_cast<const QMenuBar *>(p))
+ qobject_cast<const QMenuBar *>(p) ||
+ p->property("panelwidget").toBool())
return styleEnabled(widget);
- if (p->property("panelwidget").toBool())
- return true;
p = p->parentWidget();
}
return false;
@@ -107,10 +116,6 @@ bool styledScrollBar(const QWidget *widget)
const QWidget *p = widget;
while (p) {
- if (qobject_cast<const QToolBar *>(p) ||
- qobject_cast<const QStatusBar *>(p) ||
- qobject_cast<const QMenuBar *>(p))
- return styleEnabled(widget);
if (p->property("styledScrollBar").toBool())
return true;
p = p->parentWidget();
@@ -140,33 +145,28 @@ bool lightColored(const QWidget *widget)
class ManhattanStylePrivate
{
public:
- ManhattanStylePrivate(const QString &baseStyleName)
- {
- style = QStyleFactory::create(baseStyleName);
- QTC_ASSERT(style, /**/);
-
- lineeditImage = QImage(":/core/images/inputfield.png");
- lineeditImage_disabled = QImage(":/core/images/inputfield_disabled.png");
- }
-
- ~ManhattanStylePrivate()
- {
- delete style;
- style = 0;
- }
-
+ explicit ManhattanStylePrivate();
void init();
public:
- QStyle *style;
- QImage lineeditImage;
- QImage lineeditImage_disabled;
-
+ const QImage lineeditImage;
+ const QImage lineeditImage_disabled;
+ const QPixmap extButtonPixmap;
+ const QPixmap closeButtonPixmap;
StyleAnimator animator;
};
+ManhattanStylePrivate::ManhattanStylePrivate() :
+ lineeditImage(QLatin1String(":/core/images/inputfield.png")),
+ lineeditImage_disabled(QLatin1String(":/core/images/inputfield_disabled.png")),
+ extButtonPixmap(QLatin1String(":/core/images/extension.png")),
+ closeButtonPixmap(QLatin1String(":/core/images/closebutton.png"))
+{
+}
+
ManhattanStyle::ManhattanStyle(const QString &baseStyleName)
- : QWindowsStyle(), d(new ManhattanStylePrivate(baseStyleName))
+ : QProxyStyle(QStyleFactory::create(baseStyleName)),
+ d(new ManhattanStylePrivate())
{
}
@@ -176,74 +176,15 @@ ManhattanStyle::~ManhattanStyle()
d = 0;
}
-QStyle *ManhattanStyle::systemStyle() const
-{
- return d->style;
-}
-
-// Draws a CSS-like border image where the defined borders are not stretched
-void drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
- int left = 0, int top = 0, int right = 0,
- int bottom = 0)
-{
- QSize size = img.size();
- if (top > 0) { //top
- painter->drawImage(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), img,
- QRect(left, 0, size.width() -right - left, top));
- if (left > 0) //top-left
- painter->drawImage(QRect(rect.left(), rect.top(), left, top), img,
- QRect(0, 0, left, top));
- if (right > 0) //top-right
- painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top(), right, top), img,
- QRect(size.width() - right, 0, right, top));
- }
- //left
- if (left > 0)
- painter->drawImage(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), img,
- QRect(0, top, left, size.height() - bottom - top));
- //center
- painter->drawImage(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left,
- rect.height() - bottom - top), img,
- QRect(left, top, size.width() -right -left,
- size.height() - bottom - top));
- if (right > 0) //right
- 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));
- if (bottom > 0) { //bottom
- painter->drawImage(QRect(rect.left() +left, rect.top() + rect.height() - bottom,
- rect.width() - right - left, bottom), img,
- QRect(left, size.height() - bottom,
- size.width() - right - left, bottom));
- if (left > 0) //bottom-left
- painter->drawImage(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), img,
- 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,
- QRect(size.width() - right, size.height() - bottom, right, bottom));
- }
-}
-
QPixmap ManhattanStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
{
- QPixmap result;
- result = d->style->generatedIconPixmap(iconMode, pixmap, opt);
- return result;
-}
-
-int ManhattanStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1,
- QSizePolicy::ControlType control2,
- Qt::Orientation orientation,
- const QStyleOption * option ,
- const QWidget * widget ) const
-{
- return d->style->layoutSpacing(control1, control2, orientation, option, widget);
-
+ return QProxyStyle::generatedIconPixmap(iconMode, pixmap, opt);
}
QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &size, const QWidget *widget) const
{
- QSize newSize = d->style->sizeFromContents(type, option, size, widget);
+ QSize newSize = QProxyStyle::sizeFromContents(type, option, size, widget);
if (type == CT_Splitter && widget && widget->property("minisplitter").toBool())
return QSize(1, 1);
@@ -254,31 +195,25 @@ QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *op
QRect ManhattanStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
{
- QRect rect;
- rect = d->style->subElementRect(element, option, widget);
- return rect;
+ return QProxyStyle::subElementRect(element, option, widget);
}
QRect ManhattanStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
SubControl subControl, const QWidget *widget) const
{
- QRect rect;
- rect = d->style->subControlRect(control, option, subControl, widget);
- return rect;
+ return QProxyStyle::subControlRect(control, option, subControl, widget);
}
QStyle::SubControl ManhattanStyle::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
const QPoint &pos, const QWidget *widget) const
{
- SubControl result = QStyle::SC_None;
- result = d->style->hitTestComplexControl(control, option, pos, widget);
- return result;
+ return QProxyStyle::hitTestComplexControl(control, option, pos, widget);
}
int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
{
int retval = 0;
- retval = d->style->pixelMetric(metric, option, widget);
+ retval = QProxyStyle::pixelMetric(metric, option, widget);
switch (metric) {
case PM_SplitterWidth:
if (widget && widget->property("minisplitter").toBool())
@@ -288,6 +223,9 @@ int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
if (panelWidget(widget))
retval = 16;
break;
+ case PM_DockWidgetHandleExtent:
+ case PM_DockWidgetSeparatorExtent:
+ return 1;
case PM_MenuPanelWidth:
case PM_MenuBarHMargin:
case PM_MenuBarVMargin:
@@ -315,24 +253,22 @@ int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
QPalette ManhattanStyle::standardPalette() const
{
- QPalette result;
- result = d->style->standardPalette();
- return result;
+ return QProxyStyle::standardPalette();
}
void ManhattanStyle::polish(QApplication *app)
{
- d->style->polish(app);
+ return QProxyStyle::polish(app);
}
void ManhattanStyle::unpolish(QApplication *app)
{
- d->style->unpolish(app);
+ return QProxyStyle::unpolish(app);
}
QPalette panelPalette(const QPalette &oldPalette, bool lightColored = false)
{
- QColor color = StyleHelper::panelTextColor(lightColored);
+ QColor color = Utils::StyleHelper::panelTextColor(lightColored);
QPalette pal = oldPalette;
pal.setBrush(QPalette::All, QPalette::WindowText, color);
pal.setBrush(QPalette::All, QPalette::ButtonText, color);
@@ -346,31 +282,38 @@ QPalette panelPalette(const QPalette &oldPalette, bool lightColored = false)
void ManhattanStyle::polish(QWidget *widget)
{
- d->style->polish(widget);
+ QProxyStyle::polish(widget);
- // OxygenStyle forces a rounded widget mask on toolbars
- if (d->style->inherits("OxygenStyle")) {
- if (qobject_cast<QToolBar*>(widget))
- widget->removeEventFilter(d->style);
+ // OxygenStyle forces a rounded widget mask on toolbars and dock widgets
+ if (baseStyle()->inherits("OxygenStyle")) {
+ if (qobject_cast<QToolBar*>(widget) || qobject_cast<QDockWidget*>(widget)) {
+ widget->removeEventFilter(baseStyle());
+ widget->setContentsMargins(0, 0, 0, 0);
+ }
}
if (panelWidget(widget)) {
+
+ // Oxygen and possibly other styles override this
+ if (qobject_cast<QDockWidget*>(widget))
+ widget->setContentsMargins(0, 0, 0, 0);
+
widget->setAttribute(Qt::WA_LayoutUsesWidgetRect, true);
if (qobject_cast<QToolButton*>(widget)) {
widget->setAttribute(Qt::WA_Hover);
- widget->setMaximumHeight(StyleHelper::navigationWidgetHeight() - 1);
+ widget->setMaximumHeight(Utils::StyleHelper::navigationWidgetHeight() - 2);
}
else if (qobject_cast<QLineEdit*>(widget)) {
widget->setAttribute(Qt::WA_Hover);
- widget->setMaximumHeight(StyleHelper::navigationWidgetHeight() - 1);
+ widget->setMaximumHeight(Utils::StyleHelper::navigationWidgetHeight() - 2);
}
else if (qobject_cast<QLabel*>(widget))
widget->setPalette(panelPalette(widget->palette()));
- else if (qobject_cast<QToolBar*>(widget) || widget->property("panelwidget_singlerow").toBool())
- widget->setFixedHeight(StyleHelper::navigationWidgetHeight());
+ else if (widget->property("panelwidget_singlerow").toBool())
+ widget->setFixedHeight(Utils::StyleHelper::navigationWidgetHeight());
else if (qobject_cast<QStatusBar*>(widget))
- widget->setFixedHeight(StyleHelper::navigationWidgetHeight() + 2);
+ widget->setFixedHeight(Utils::StyleHelper::navigationWidgetHeight() + 2);
else if (qobject_cast<QComboBox*>(widget)) {
- widget->setMaximumHeight(StyleHelper::navigationWidgetHeight() - 1);
+ widget->setMaximumHeight(Utils::StyleHelper::navigationWidgetHeight() - 2);
widget->setAttribute(Qt::WA_Hover);
}
}
@@ -378,7 +321,7 @@ void ManhattanStyle::polish(QWidget *widget)
void ManhattanStyle::unpolish(QWidget *widget)
{
- d->style->unpolish(widget);
+ QProxyStyle::unpolish(widget);
if (panelWidget(widget)) {
widget->setAttribute(Qt::WA_LayoutUsesWidgetRect, false);
if (qobject_cast<QTabBar*>(widget))
@@ -392,11 +335,10 @@ void ManhattanStyle::unpolish(QWidget *widget)
void ManhattanStyle::polish(QPalette &pal)
{
- d->style->polish(pal);
+ QProxyStyle::polish(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;
switch (standardIcon) {
@@ -404,7 +346,7 @@ QIcon ManhattanStyle::standardIconImplementation(StandardPixmap standardIcon, co
case QStyle::SP_ToolBarHorizontalExtensionButton:
return QIcon(standardPixmap(standardIcon, option, widget));
default:
- icon = d->style->standardIcon(standardIcon, option, widget);
+ icon = baseStyle()->standardIcon(standardIcon, option, widget);
}
return icon;
}
@@ -413,31 +355,27 @@ QPixmap ManhattanStyle::standardPixmap(StandardPixmap standardPixmap, const QSty
const QWidget *widget) const
{
if (widget && !panelWidget(widget))
- return d->style->standardPixmap(standardPixmap, opt, widget);
+ return QProxyStyle::standardPixmap(standardPixmap, opt, widget);
QPixmap pixmap;
switch (standardPixmap) {
- case QStyle::SP_ToolBarHorizontalExtensionButton: {
- static const QPixmap extButton(":/core/images/extension.png");
- pixmap = extButton;
- }
+ case QStyle::SP_ToolBarHorizontalExtensionButton:
+ pixmap = d->extButtonPixmap;
break;
- case QStyle::SP_TitleBarCloseButton: {
- static const QPixmap closeButton(":/style/images/closebutton.png");
- pixmap = closeButton;
- }
+ case QStyle::SP_TitleBarCloseButton:
+ pixmap = d->closeButtonPixmap;
break;
default:
- pixmap = d->style->standardPixmap(standardPixmap, opt, widget);
+ pixmap = QProxyStyle::standardPixmap(standardPixmap, opt, widget);
+ break;
}
return pixmap;
}
-
int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
QStyleHintReturn *returnData) const
{
- int ret = d->style->styleHint(hint, option, widget, returnData);
+ int ret = QProxyStyle::styleHint(hint, option, widget, returnData);
switch (hint) {
// Make project explorer alternate rows all the way
case QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea:
@@ -448,6 +386,9 @@ int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const
if (panelWidget(widget))
ret = false;
break;
+ case QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren:
+ ret = true;
+ break;
default:
break;
}
@@ -458,7 +399,7 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
QPainter *painter, const QWidget *widget) const
{
if (!panelWidget(widget))
- return d->style->drawPrimitive(element, option, painter, widget);
+ return QProxyStyle::drawPrimitive(element, option, painter, widget);
bool animating = (option->state & State_Animating);
int state = option->state;
@@ -516,6 +457,12 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
}
switch (element) {
+ case PE_IndicatorDockWidgetResizeHandle:
+ painter->fillRect(option->rect, Utils::StyleHelper::borderColor());
+ break;
+ case PE_FrameDockWidget:
+ QCommonStyle::drawPrimitive(element, option, painter, widget);
+ break;
case PE_PanelLineEdit:
{
painter->save();
@@ -526,12 +473,12 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
painter->fillRect(filledRect, option->palette.base());
if (option->state & State_Enabled)
- drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5);
+ Utils::StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5);
else
- 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 = StyleHelper::baseColor();
+ QColor hover = Utils::StyleHelper::baseColor();
if (state & State_HasFocus)
hover.setAlpha(100);
else
@@ -570,6 +517,17 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
QColor lighter(255, 255, 255, 37);
painter->fillRect(rect, lighter);
}
+ if (option->state & State_HasFocus && (option->state & State_KeyboardFocusChange)) {
+ QColor highlight = option->palette.highlight().color();
+ highlight.setAlphaF(0.4);
+ painter->setPen(QPen(highlight.lighter(), 1));
+ highlight.setAlphaF(0.3);
+ painter->setBrush(highlight);
+ painter->setRenderHint(QPainter::Antialiasing);
+ QRectF rect = option->rect;
+ rect.translate(0.5, 0.5);
+ painter->drawRoundedRect(rect.adjusted(2, 2, -3, -3), 2, 2);
+ }
}
}
break;
@@ -578,15 +536,15 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
{
painter->save();
QLinearGradient grad(option->rect.topLeft(), QPoint(rect.center().x(), rect.bottom()));
- QColor startColor = StyleHelper::shadowColor().darker(164);
- QColor endColor = StyleHelper::baseColor().darker(130);
+ QColor startColor = Utils::StyleHelper::shadowColor().darker(164);
+ QColor endColor = Utils::StyleHelper::baseColor().darker(130);
grad.setColorAt(0, startColor);
grad.setColorAt(1, endColor);
painter->fillRect(option->rect, grad);
painter->setPen(QColor(255, 255, 255, 60));
painter->drawLine(rect.topLeft() + QPoint(0,1),
rect.topRight()+ QPoint(0,1));
- painter->setPen(StyleHelper::borderColor().darker(110));
+ painter->setPen(Utils::StyleHelper::borderColor().darker(110));
painter->drawLine(rect.topLeft(), rect.topRight());
painter->restore();
}
@@ -594,7 +552,7 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
case PE_IndicatorToolBarSeparator:
{
- QColor separatorColor = StyleHelper::borderColor();
+ QColor separatorColor = Utils::StyleHelper::borderColor();
separatorColor.setAlpha(100);
painter->setPen(separatorColor);
const int margin = 6;
@@ -638,10 +596,10 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
}
painter->setPen(Qt::NoPen);
- QColor dark = StyleHelper::borderColor();
+ QColor dark = Utils::StyleHelper::borderColor();
dark.setAlphaF(0.4);
- QColor light = StyleHelper::baseColor();
+ QColor light = Utils::StyleHelper::baseColor();
light.setAlphaF(0.4);
painter->fillPath(path, light);
@@ -661,85 +619,12 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
case PE_IndicatorArrowRight:
case PE_IndicatorArrowLeft:
{
- // From windowsstyle but modified to enable AA
- if (option->rect.width() <= 1 || option->rect.height() <= 1)
- break;
-
- QRect r = option->rect;
- int size = qMin(r.height(), r.width());
- QPixmap pixmap;
- QString pixmapName;
- pixmapName.sprintf("%s-%s-%d-%d-%d-%lld",
- "$qt_ia", metaObject()->className(),
- uint(option->state), element,
- size, option->palette.cacheKey());
- if (!QPixmapCache::find(pixmapName, pixmap)) {
- int border = size/5;
- int sqsize = 2*(size/2);
- QImage image(sqsize, sqsize, QImage::Format_ARGB32);
- image.fill(Qt::transparent);
- QPainter imagePainter(&image);
- imagePainter.setRenderHint(QPainter::Antialiasing, true);
- imagePainter.translate(0.5, 0.5);
- QPolygon a;
- switch (element) {
- case PE_IndicatorArrowUp:
- a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2);
- break;
- case PE_IndicatorArrowDown:
- a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2);
- break;
- case PE_IndicatorArrowRight:
- a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
- break;
- case PE_IndicatorArrowLeft:
- a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
- break;
- default:
- break;
- }
-
- int bsx = 0;
- int bsy = 0;
-
- if (option->state & State_Sunken) {
- bsx = pixelMetric(PM_ButtonShiftHorizontal);
- bsy = pixelMetric(PM_ButtonShiftVertical);
- }
-
- QRect bounds = a.boundingRect();
- int sx = sqsize / 2 - bounds.center().x() - 1;
- int sy = sqsize / 2 - bounds.center().y() - 1;
- imagePainter.translate(sx + bsx, sy + bsy);
-
- if (!(option->state & State_Enabled)) {
- QColor foreGround(150, 150, 150, 150);
- imagePainter.setBrush(option->palette.mid().color());
- imagePainter.setPen(option->palette.mid().color());
- } else {
- QColor shadow(0, 0, 0, 100);
- imagePainter.translate(0, 1);
- imagePainter.setPen(shadow);
- imagePainter.setBrush(shadow);
- QColor foreGround(255, 255, 255, 210);
- imagePainter.drawPolygon(a);
- imagePainter.translate(0, -1);
- imagePainter.setPen(foreGround);
- imagePainter.setBrush(foreGround);
- }
- imagePainter.drawPolygon(a);
- imagePainter.end();
- pixmap = QPixmap::fromImage(image);
- QPixmapCache::insert(pixmapName, pixmap);
- }
- int xOffset = r.x() + (r.width() - size)/2;
- int yOffset = r.y() + (r.height() - size)/2;
- painter->drawPixmap(xOffset, yOffset, pixmap);
+ Utils::StyleHelper::drawArrow(element, painter, option);
}
break;
default:
- d->style->drawPrimitive(element, option, painter, widget);
+ QProxyStyle::drawPrimitive(element, option, painter, widget);
break;
}
}
@@ -747,18 +632,41 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const
{
- if (!panelWidget(widget)
- && !styledScrollBar(widget))
- return d->style->drawControl(element, option, painter, widget);
+ if (!panelWidget(widget) && !styledScrollBar(widget))
+ return QProxyStyle::drawControl(element, option, painter, widget);
switch (element) {
+ case CE_Splitter:
+ painter->fillRect(option->rect, Utils::StyleHelper::borderColor());
+ break;
+
+ case CE_TabBarTabShape:
+ // 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
+
+ if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) {
+ QStyleOptionTabV3 adjustedTab = *tab;
+ if (tab->cornerWidgets == QStyleOptionTab::NoCornerWidgets && (
+ tab->position == QStyleOptionTab::Beginning ||
+ tab->position == QStyleOptionTab::OnlyOneTab))
+ {
+ if (option->direction == Qt::LeftToRight)
+ adjustedTab.rect = adjustedTab.rect.adjusted(-1, 0, 0, 0);
+ else
+ adjustedTab.rect = adjustedTab.rect.adjusted(0, 0, 1 ,0);
+ }
+ QProxyStyle::drawControl(element, &adjustedTab, painter, widget);
+ return;
+ }
+ break;
+
case CE_MenuBarItem:
painter->save();
if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
- QColor highlightOutline = StyleHelper::borderColor().lighter(120);
+ QColor highlightOutline = Utils::StyleHelper::borderColor().lighter(120);
bool act = mbi->state & State_Selected && mbi->state & State_Sunken;
bool dis = !(mbi->state & State_Enabled);
- StyleHelper::menuGradient(painter, option->rect, option->rect);
+ Utils::StyleHelper::menuGradient(painter, option->rect, option->rect);
QStyleOptionMenuItem item = *mbi;
item.rect = mbi->rect;
QPalette pal = mbi->palette;
@@ -769,7 +677,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
if (act) {
// Fill|
- QColor baseColor = StyleHelper::baseColor();
+ QColor baseColor = Utils::StyleHelper::baseColor();
QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft());
grad.setColorAt(0, baseColor.lighter(120));
grad.setColorAt(1, baseColor.lighter(130));
@@ -801,6 +709,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
case CE_ComboBoxLabel:
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
if (panelWidget(widget)) {
+ painter->save();
QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
QPalette customPal = cb->palette;
@@ -826,18 +735,19 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
editRect.adjust(0, 0, -13, 0);
}
- customPal.setBrush(QPalette::All, QPalette::ButtonText, QColor(0, 0, 0, 70));
-
QString text = option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, editRect.width());
- drawItemText(painter, editRect.translated(0, 1),
- visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter),
- customPal, cb->state & State_Enabled, text, QPalette::ButtonText);
- customPal.setBrush(QPalette::All, QPalette::ButtonText, StyleHelper::panelTextColor());
- drawItemText(painter, editRect,
- visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter),
- customPal, cb->state & State_Enabled, text, QPalette::ButtonText);
+ if ((option->state & State_Enabled)) {
+ painter->setPen(QColor(0, 0, 0, 70));
+ painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, cb->currentText);
+ } else {
+ painter->setOpacity(0.8);
+ }
+ painter->setPen(Utils::StyleHelper::panelTextColor());
+ painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, cb->currentText);
+
+ painter->restore();
} else {
- d->style->drawControl(element, option, painter, widget);
+ QProxyStyle::drawControl(element, option, painter, widget);
}
}
break;
@@ -876,9 +786,9 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
break;
case CE_MenuBarEmptyArea: {
- StyleHelper::menuGradient(painter, option->rect, option->rect);
+ Utils::StyleHelper::menuGradient(painter, option->rect, option->rect);
painter->save();
- painter->setPen(StyleHelper::borderColor());
+ painter->setPen(Utils::StyleHelper::borderColor());
painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
painter->restore();
}
@@ -886,56 +796,35 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
case CE_ToolBar:
{
- QString key;
- QColor keyColor = StyleHelper::baseColor(lightColored(widget));
- key.sprintf("mh_toolbar %d %d %d", option->rect.width(), option->rect.height(), keyColor.rgb());;
-
- QPixmap pixmap;
- QPainter *p = painter;
QRect rect = option->rect;
bool horizontal = option->state & State_Horizontal;
- if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
- pixmap = QPixmap(option->rect.size());
- p = new QPainter(&pixmap);
- rect = QRect(0, 0, option->rect.width(), option->rect.height());
- }
-
- if (!StyleHelper::usePixmapCache() || !QPixmapCache::find(key, pixmap)) {
- // Map offset for global window gradient
- QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
- widget->mapToGlobal(option->rect.topLeft());
- QRect gradientSpan;
- if (widget) {
- gradientSpan = QRect(offset, widget->window()->size());
- }
- bool drawLightColored = lightColored(widget);
- if (horizontal)
- StyleHelper::horizontalGradient(p, gradientSpan, rect, drawLightColored);
- else
- StyleHelper::verticalGradient(p, gradientSpan, rect, drawLightColored);
- }
-
- if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
- delete p;
- QPixmapCache::insert(key, pixmap);
- }
- if (StyleHelper::usePixmapCache()) {
- painter->drawPixmap(rect.topLeft(), pixmap);
- }
-
- bool lightColored = (widget && widget->property("lightColored").toBool());
+ rect = option->rect;
+
+ // Map offset for global window gradient
+ QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) -
+ widget->mapToGlobal(option->rect.topLeft());
+ QRect gradientSpan;
+ if (widget)
+ 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 (lightColored)
- painter->setPen(QColor(0x888888));
+ if (!drawLightColored)
+ painter->setPen(Utils::StyleHelper::borderColor());
else
- painter->setPen(StyleHelper::borderColor());
+ 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(255, 255, 255, lightColored ? 180 : 40);
+ 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);
@@ -949,40 +838,52 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
painter->drawLine(rect.topLeft(), rect.bottomLeft());
painter->drawLine(rect.topRight(), rect.bottomRight());
}
- painter->end();
}
break;
case CE_ScrollBarAddLine:
case CE_ScrollBarSubLine: {
- PrimitiveElement arrow;
- if (option->state & State_Horizontal) {
- if (element == CE_ScrollBarAddLine)
- arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
- else
- arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
- } else {
- if (element == CE_ScrollBarAddLine)
- arrow = PE_IndicatorArrowDown;
- else
- arrow = PE_IndicatorArrowUp;
+ PrimitiveElement arrow;
+ if (option->state & State_Horizontal) {
+ if (element == CE_ScrollBarAddLine)
+ arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
+ else
+ arrow = option->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
+ } else {
+ if (element == CE_ScrollBarAddLine)
+ arrow = PE_IndicatorArrowDown;
+ else
+ arrow = PE_IndicatorArrowUp;
+ }
+ QStyleOption arrowOpt = *option;
+ arrowOpt.palette.setColor(QPalette::Active, QPalette::ButtonText, Utils::StyleHelper::baseColor());
+ arrowOpt.palette.setColor(QPalette::Disabled, QPalette::ButtonText, Utils::StyleHelper::shadowColor());
+ int squareSide = qMin(option->rect.width(), option->rect.height());
+ arrowOpt.rect.setSize(QSize(squareSide, squareSide));
+ arrowOpt.rect.adjust(5, 5, -1, -3);
+
+ drawPrimitive(arrow, &arrowOpt, painter, widget);
}
- QStyleOption arrowOpt = *option;
- arrowOpt.palette.setColor(QPalette::Active, QPalette::ButtonText, StyleHelper::baseColor());
- arrowOpt.palette.setColor(QPalette::Disabled, QPalette::ButtonText, StyleHelper::shadowColor());
- int squareSide = qMin(option->rect.width(), option->rect.height());
- arrowOpt.rect.setSize(QSize(squareSide, squareSide));
- arrowOpt.rect.adjust(5, 5, -1, -3);
-
- drawPrimitive(arrow, &arrowOpt, painter, widget);
- break; }
+ break;
+
case CE_ScrollBarSlider: {
- QRect rect = option->rect.adjusted(5, 0, -3, 0);
- if (option->state & State_Enabled) {
- StyleHelper::drawSlider(painter, rect);
+ QRect rect = option->rect.adjusted(5, 0, -3, 0);
+ if (option->state & State_Enabled) {
+ painter->save();
+ QColor base = Utils::StyleHelper::baseColor();
+ QLinearGradient grad(rect.topRight(), rect.topLeft());
+ grad.setColorAt(0, base.lighter());
+ grad.setColorAt(1, base.lighter(190));
+ painter->setRenderHint(QPainter::Antialiasing);
+ painter->setBrush(grad);
+ painter->setPen(Qt::NoPen);
+ painter->drawRoundedRect(rect, 3, 3);
+ painter->restore();
+ }
}
- break; }
+ break;
+
default:
- d->style->drawControl(element, option, painter, widget);
+ QProxyStyle::drawControl(element, option, painter, widget);
break;
}
}
@@ -991,7 +892,7 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
QPainter *painter, const QWidget *widget) const
{
if (!panelWidget(widget) && !styledScrollBar(widget))
- return d->style->drawComplexControl(control, option, painter, widget);
+ return QProxyStyle::drawComplexControl(control, option, painter, widget);
QRect rect = option->rect;
switch (control) {
@@ -1024,30 +925,12 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
}
- if (toolbutton->state & State_HasFocus) {
- QStyleOptionFocusRect fr;
- fr.QStyleOption::operator=(*toolbutton);
- fr.rect.adjust(3, 3, -3, -3);
- if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
- fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator,
- toolbutton, widget), 0);
- QPen oldPen = painter->pen();
- QColor focusColor = StyleHelper::panelTextColor();
- focusColor.setAlpha(120);
- QPen outline(focusColor, 1);
- outline.setStyle(Qt::DotLine);
- painter->setPen(outline);
- QRect r = option->rect.adjusted(2, 2, -2, -2);
- painter->drawRect(r);
- painter->setPen(oldPen);
- }
-
QStyleOptionToolButton label = *toolbutton;
-
+
label.palette = panelPalette(option->palette, lightColored(widget));
int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
label.rect = button.adjusted(fw, fw, -fw, -fw);
-
+
drawControl(CE_ToolButtonLabel, &label, painter, widget);
if (toolbutton->subControls & SC_ToolButtonMenu) {
@@ -1070,7 +953,7 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
tool.rect = tool.rect.adjusted(2, 2, -2, -2);
drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
} else if (toolbutton->features & QStyleOptionToolButton::HasMenu
- && !widget->property("noArrow").toBool()) {
+ && !widget->property("noArrow").toBool()) {
int arrowSize = 6;
QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1);
QStyleOptionToolButton newBtn = *toolbutton;
@@ -1087,29 +970,34 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
painter->save();
bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull();
bool reverse = option->direction == Qt::RightToLeft;
+ bool drawborder = !(widget && widget->property("hideborder").toBool());
+ bool alignarrow = !(widget && widget->property("alignarrow").toBool());
// Draw tool button
- QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight());
- grad.setColorAt(0, QColor(255, 255, 255, 20));
- grad.setColorAt(0.4, QColor(255, 255, 255, 60));
- grad.setColorAt(0.7, QColor(255, 255, 255, 50));
- grad.setColorAt(1, QColor(255, 255, 255, 40));
- painter->setPen(QPen(grad, 0));
- painter->drawLine(rect.topRight(), rect.bottomRight());
- grad.setColorAt(0, QColor(0, 0, 0, 30));
- grad.setColorAt(0.4, QColor(0, 0, 0, 70));
- grad.setColorAt(0.7, QColor(0, 0, 0, 70));
- grad.setColorAt(1, QColor(0, 0, 0, 40));
- painter->setPen(QPen(grad, 0));
- if (!reverse)
- painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0));
- else
- painter->drawLine(rect.topLeft(), rect.bottomLeft());
+ if (drawborder) {
+ QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight());
+ grad.setColorAt(0, QColor(255, 255, 255, 20));
+ grad.setColorAt(0.4, QColor(255, 255, 255, 60));
+ grad.setColorAt(0.7, QColor(255, 255, 255, 50));
+ grad.setColorAt(1, QColor(255, 255, 255, 40));
+ painter->setPen(QPen(grad, 0));
+ painter->drawLine(rect.topRight(), rect.bottomRight());
+ grad.setColorAt(0, QColor(0, 0, 0, 30));
+ grad.setColorAt(0.4, QColor(0, 0, 0, 70));
+ grad.setColorAt(0.7, QColor(0, 0, 0, 70));
+ grad.setColorAt(1, QColor(0, 0, 0, 40));
+ painter->setPen(QPen(grad, 0));
+ if (!reverse)
+ painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0));
+ else
+ painter->drawLine(rect.topLeft(), rect.bottomLeft());
+ }
QStyleOption toolbutton = *option;
if (isEmpty)
toolbutton.state &= ~(State_Enabled | State_Sunken);
painter->save();
- painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0));
+ if (drawborder)
+ painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0));
drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget);
painter->restore();
// Draw arrow
@@ -1117,9 +1005,14 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9);
+
+ if (!alignarrow) {
+ int leftOffset = option->fontMetrics.width(cb->currentText) + 12;
+ arrowRect.moveLeft(leftOffset);
+ }
if (option->state & State_On)
- arrowRect.translate(d->style->pixelMetric(PM_ButtonShiftHorizontal, option, widget),
- d->style->pixelMetric(PM_ButtonShiftVertical, option, widget));
+ arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget),
+ QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget));
QStyleOption arrowOpt = *option;
arrowOpt.rect = arrowRect;
@@ -1134,18 +1027,31 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
} else {
drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
}
+
painter->restore();
}
break;
+
case CC_ScrollBar:
if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
+ painter->save();
// Make a copy here and reset it for each primitive.
QStyleOptionSlider newScrollbar = *scrollbar;
State saveFlags = scrollbar->state;
if (scrollbar->minimum == scrollbar->maximum)
saveFlags &= ~State_Enabled;
- StyleHelper::rectWithLeftLine(widget, painter, newScrollbar.rect);
+
+ painter->save();
+ painter->setBrush(QBrush(widget->palette().background()));
+ painter->setPen(Qt::NoPen);
+ painter->drawRect(rect);
+ QPen pen = painter->pen();
+ pen.setColor(Utils::StyleHelper::highlightColor().lighter());
+ pen.setStyle(Qt::SolidLine);
+ painter->setPen(pen);
+ painter->drawLine(rect.topLeft(), rect.bottomLeft());
+ painter->restore();
if (scrollbar->subControls & SC_ScrollBarSubLine) {
newScrollbar.state = saveFlags;
@@ -1176,18 +1082,12 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
drawControl(CE_ScrollBarSlider, &newScrollbar, painter, widget);
}
}
+ painter->restore();
}
break;
+
default:
- d->style->drawComplexControl(control, option, painter, widget);
+ QProxyStyle::drawComplexControl(control, option, painter, widget);
break;
}
}
-
-// Mac style reimplements this to control the
-// focus widget among other things
-bool ManhattanStyle::event(QEvent *e)
-{
- Q_ASSERT(d->style);
- return d->style->event(e);
-}
diff --git a/library/style/manhattanstyle.h b/library/style/manhattanstyle.h
index 8019066..30879e5 100644
--- a/library/style/manhattanstyle.h
+++ b/library/style/manhattanstyle.h
@@ -30,7 +30,7 @@
#ifndef MANHATTANSTYLE_H
#define MANHATTANSTYLE_H
-#include <QtGui/QWindowsStyle>
+#include <QtGui/QProxyStyle>
QT_BEGIN_NAMESPACE
class QLinearGradient;
@@ -39,7 +39,7 @@ QT_END_NAMESPACE
class ManhattanStylePrivate;
-class ManhattanStyle : public QWindowsStyle
+class ManhattanStyle : public QProxyStyle
{
Q_OBJECT
@@ -48,8 +48,6 @@ public:
~ManhattanStyle();
- QStyle *systemStyle() const;
-
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = 0) const;
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = 0) const;
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget = 0) const;
@@ -74,17 +72,8 @@ public:
void unpolish(QWidget *widget);
void unpolish(QApplication *app);
-
-protected:
- bool event(QEvent *e);
-
protected Q_SLOTS:
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const;
- int layoutSpacingImplementation(QSizePolicy::ControlType control1,
- QSizePolicy::ControlType control2,
- Qt::Orientation orientation,
- const QStyleOption *option = 0,
- const QWidget *widget = 0) const;
private:
ManhattanStylePrivate *d;
diff --git a/library/style/styleanimator.h b/library/style/styleanimator.h
index aad3ee3..29b2577 100644
--- a/library/style/styleanimator.h
+++ b/library/style/styleanimator.h
@@ -37,13 +37,13 @@
#include <QtGui/QPainter>
#include <QtGui/QWidget>
-/*
+/*
* This is a set of helper classes to allow for widget animations in
* the style. Its mostly taken from Vista style so it should be fully documented
* there.
*
*/
-
+
class Animation
{
public :
@@ -92,7 +92,7 @@ public:
void startAnimation(Animation *);
void stopAnimation(const QWidget *);
Animation* widgetAnimation(const QWidget *) const;
-
+
private:
QBasicTimer animationTimer;
QList <Animation*> animations;
diff --git a/library/style/styledbar.cpp b/library/style/styledbar.cpp
index bcde0e5..0fd0426 100644
--- a/library/style/styledbar.cpp
+++ b/library/style/styledbar.cpp
@@ -37,6 +37,8 @@
#include <QtGui/QStyle>
#include <QtGui/QStyleOption>
+using namespace Utils;
+
StyledBar::StyledBar(QWidget *parent)
: QWidget(parent)
{
diff --git a/library/style/styledbar.h b/library/style/styledbar.h
index 19b1d3c..61edfa1 100644
--- a/library/style/styledbar.h
+++ b/library/style/styledbar.h
@@ -32,8 +32,11 @@
#include <QtGui/QWidget>
+namespace Utils {
+
class StyledBar : public QWidget
{
+ Q_OBJECT
public:
StyledBar(QWidget *parent = 0);
void setSingleRow(bool singleRow);
@@ -48,10 +51,13 @@ protected:
class StyledSeparator : public QWidget
{
+ Q_OBJECT
public:
StyledSeparator(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *event);
};
+} // Utils
+
#endif // STYLEDBAR_H
diff --git a/library/style/stylehelper.cpp b/library/style/stylehelper.cpp
index dfde259..05d8646 100644
--- a/library/style/stylehelper.cpp
+++ b/library/style/stylehelper.cpp
@@ -35,6 +35,8 @@
#include <QtGui/QPainter>
#include <QtGui/QApplication>
#include <QtGui/QPalette>
+#include <QtGui/QStyleOption>
+#include <QtCore/QObject>
// Clamps float color values within (0, 255)
static int clamp(float x)
@@ -52,6 +54,8 @@ static int range(float x, int min, int max)
}
*/
+namespace Utils {
+
QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int factor)
{
const int maxFactor = 100;
@@ -65,7 +69,7 @@ QColor StyleHelper::mergedColors(const QColor &colorA, const QColor &colorB, int
qreal StyleHelper::sidebarFontSize()
{
#if defined(Q_WS_MAC)
- return 9;
+ return 10;
#else
return 7.5;
#endif
@@ -91,6 +95,7 @@ QColor StyleHelper::panelTextColor(bool lightColored)
}
QColor StyleHelper::m_baseColor(0x666666);
+QColor StyleHelper::m_requestedBaseColor(0x666666);
QColor StyleHelper::baseColor(bool lightColored)
{
@@ -132,8 +137,18 @@ QColor StyleHelper::borderColor(bool lightColored)
return result;
}
-void StyleHelper::setBaseColor(const QColor &color)
+// We try to ensure that the actual color used are within
+// reasonalbe bounds while generating the actual baseColor
+// from the users request.
+void StyleHelper::setBaseColor(const QColor &newcolor)
{
+ m_requestedBaseColor = newcolor;
+
+ QColor color;
+ color.setHsv(newcolor.hue(),
+ newcolor.saturation() * 0.7,
+ 64 + newcolor.value() / 3);
+
if (color.isValid() && color != m_baseColor) {
m_baseColor = color;
foreach (QWidget *w, QApplication::topLevelWidgets())
@@ -143,25 +158,26 @@ void StyleHelper::setBaseColor(const QColor &color)
static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect, bool lightColored)
{
- QColor base = StyleHelper::baseColor(lightColored);
QColor highlight = StyleHelper::highlightColor(lightColored);
QColor shadow = StyleHelper::shadowColor(lightColored);
QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
- grad.setColorAt(0, highlight);
- grad.setColorAt(0.301, base);
- grad.setColorAt(1, shadow);
+ grad.setColorAt(0, highlight.lighter(117));
+ grad.setColorAt(1, shadow.darker(109));
p->fillRect(rect, grad);
QColor light(255, 255, 255, 80);
p->setPen(light);
p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0));
+ QColor dark(0, 0, 0, 90);
+ p->setPen(dark);
+ p->drawLine(rect.topLeft(), rect.bottomLeft());
}
void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored)
{
if (StyleHelper::usePixmapCache()) {
QString key;
- QColor keyColor = StyleHelper::baseColor(lightColored);
+ QColor keyColor = baseColor(lightColored);
key.sprintf("mh_vertical %d %d %d %d %d",
spanRect.width(), spanRect.height(), clipRect.width(),
clipRect.height(), keyColor.rgb());;
@@ -222,10 +238,10 @@ void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, c
{
if (StyleHelper::usePixmapCache()) {
QString key;
- QColor keyColor = StyleHelper::baseColor(lightColored);
- key.sprintf("mh_horizontal %d %d %d %d %d",
+ QColor keyColor = baseColor(lightColored);
+ key.sprintf("mh_horizontal %d %d %d %d %d %d",
spanRect.width(), spanRect.height(), clipRect.width(),
- clipRect.height(), keyColor.rgb());
+ clipRect.height(), keyColor.rgb(), spanRect.x());
QPixmap pixmap;
if (!QPixmapCache::find(key, pixmap)) {
@@ -253,6 +269,84 @@ static void menuGradientHelper(QPainter *p, const QRect &spanRect, const QRect &
p->fillRect(rect, grad);
}
+void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option)
+{
+ // From windowsstyle but modified to enable AA
+ if (option->rect.width() <= 1 || option->rect.height() <= 1)
+ return;
+
+ QRect r = option->rect;
+ int size = qMin(r.height(), r.width());
+ QPixmap pixmap;
+ QString pixmapName;
+ pixmapName.sprintf("arrow-%s-%d-%d-%d-%lld",
+ "$qt_ia",
+ uint(option->state), element,
+ size, option->palette.cacheKey());
+ if (!QPixmapCache::find(pixmapName, pixmap)) {
+ int border = size/5;
+ int sqsize = 2*(size/2);
+ QImage image(sqsize, sqsize, QImage::Format_ARGB32);
+ image.fill(Qt::transparent);
+ QPainter imagePainter(&image);
+ imagePainter.setRenderHint(QPainter::Antialiasing, true);
+ imagePainter.translate(0.5, 0.5);
+ QPolygon a;
+ switch (element) {
+ case QStyle::PE_IndicatorArrowUp:
+ a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2);
+ break;
+ case QStyle::PE_IndicatorArrowDown:
+ a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2);
+ break;
+ case QStyle::PE_IndicatorArrowRight:
+ a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
+ break;
+ case QStyle::PE_IndicatorArrowLeft:
+ a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
+ break;
+ default:
+ break;
+ }
+
+ int bsx = 0;
+ int bsy = 0;
+
+ if (option->state & QStyle::State_Sunken) {
+ bsx = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal);
+ bsy = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftVertical);
+ }
+
+ QRect bounds = a.boundingRect();
+ int sx = sqsize / 2 - bounds.center().x() - 1;
+ int sy = sqsize / 2 - bounds.center().y() - 1;
+ imagePainter.translate(sx + bsx, sy + bsy);
+
+ if (!(option->state & QStyle::State_Enabled)) {
+ QColor foreGround(150, 150, 150, 150);
+ imagePainter.setBrush(option->palette.mid().color());
+ imagePainter.setPen(option->palette.mid().color());
+ } else {
+ QColor shadow(0, 0, 0, 100);
+ imagePainter.translate(0, 1);
+ imagePainter.setPen(shadow);
+ imagePainter.setBrush(shadow);
+ QColor foreGround(255, 255, 255, 210);
+ imagePainter.drawPolygon(a);
+ imagePainter.translate(0, -1);
+ imagePainter.setPen(foreGround);
+ imagePainter.setBrush(foreGround);
+ }
+ imagePainter.drawPolygon(a);
+ imagePainter.end();
+ pixmap = QPixmap::fromImage(image);
+ QPixmapCache::insert(pixmapName, pixmap);
+ }
+ int xOffset = r.x() + (r.width() - size)/2;
+ int yOffset = r.y() + (r.height() - size)/2;
+ painter->drawPixmap(xOffset, yOffset, pixmap);
+}
+
void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
{
if (StyleHelper::usePixmapCache()) {
@@ -277,28 +371,114 @@ void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const Q
}
}
-void StyleHelper::rectWithLeftLine(const QWidget *widget, QPainter *painter, const QRect &rect)
+// Draws a cached pixmap with shadow
+void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
+ QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset)
{
- painter->save();
- painter->setBrush(QBrush(widget->palette().background()));
- painter->setPen(Qt::NoPen);
- painter->drawRect(rect);
- QPen pen = painter->pen();
- pen.setColor(highlightColor().lighter());
- pen.setStyle(Qt::SolidLine);
- painter->setPen(pen);
- painter->drawLine(rect.topLeft(), rect.bottomLeft());
- painter->restore();
+ QPixmap cache;
+ QString pixmapName = QString("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());
+
+ if (!QPixmapCache::find(pixmapName, cache)) {
+ QPixmap px = icon.pixmap(rect.size());
+ cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
+ cache.fill(Qt::transparent);
+
+ QPainter cachePainter(&cache);
+ if (iconMode == QIcon::Disabled) {
+ QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
+ for (int y=0; y<im.height(); ++y) {
+ QRgb *scanLine = (QRgb*)im.scanLine(y);
+ for (int x=0; x<im.width(); ++x) {
+ QRgb pixel = *scanLine;
+ char intensity = qGray(pixel);
+ *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
+ ++scanLine;
+ }
+ }
+ px = QPixmap::fromImage(im);
+ }
+
+ // Draw shadow
+ QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
+ tmp.fill(Qt::transparent);
+
+ QPainter tmpPainter(&tmp);
+ tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
+ tmpPainter.drawPixmap(QPoint(radius, radius), px);
+ tmpPainter.end();
+
+ // blur the alpha channel
+ QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
+ blurred.fill(Qt::transparent);
+ QPainter blurPainter(&blurred);
+ qt_blurImage(&blurPainter, tmp, radius, false, true);
+ blurPainter.end();
+
+ tmp = blurred;
+
+ // blacken the image...
+ tmpPainter.begin(&tmp);
+ tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ tmpPainter.fillRect(tmp.rect(), color);
+ tmpPainter.end();
+
+ tmpPainter.begin(&tmp);
+ tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ tmpPainter.fillRect(tmp.rect(), color);
+ tmpPainter.end();
+
+ // draw the blurred drop shadow...
+ cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);
+
+ // Draw the actual pixmap...
+ cachePainter.drawPixmap(QPoint(radius, radius) + offset, px);
+ QPixmapCache::insert(pixmapName, cache);
+ }
+
+ QRect targetRect = cache.rect();
+ targetRect.moveCenter(rect.center());
+ p->drawPixmap(targetRect.topLeft() - offset, cache);
}
-void StyleHelper::drawSlider(QPainter *painter, const QRect &rect)
+// Draws a CSS-like border image where the defined borders are not stretched
+void StyleHelper::drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
+ int left, int top, int right, int bottom)
{
- QColor base = StyleHelper::baseColor();
- QLinearGradient grad(rect.topRight(), rect.topLeft());
- grad.setColorAt(0, base.lighter());
- grad.setColorAt(1, base.lighter(190));
- painter->setRenderHint(QPainter::Antialiasing);
- painter->setBrush(grad);
- painter->setPen(Qt::NoPen);
- painter->drawRoundedRect(rect, 3, 3);
+ QSize size = img.size();
+ if (top > 0) { //top
+ painter->drawImage(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), img,
+ QRect(left, 0, size.width() -right - left, top));
+ if (left > 0) //top-left
+ painter->drawImage(QRect(rect.left(), rect.top(), left, top), img,
+ QRect(0, 0, left, top));
+ if (right > 0) //top-right
+ painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top(), right, top), img,
+ QRect(size.width() - right, 0, right, top));
+ }
+ //left
+ if (left > 0)
+ painter->drawImage(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), img,
+ QRect(0, top, left, size.height() - bottom - top));
+ //center
+ painter->drawImage(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left,
+ rect.height() - bottom - top), img,
+ QRect(left, top, size.width() -right -left,
+ size.height() - bottom - top));
+ if (right > 0) //right
+ 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));
+ if (bottom > 0) { //bottom
+ painter->drawImage(QRect(rect.left() +left, rect.top() + rect.height() - bottom,
+ rect.width() - right - left, bottom), img,
+ QRect(left, size.height() - bottom,
+ size.width() - right - left, bottom));
+ if (left > 0) //bottom-left
+ painter->drawImage(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), img,
+ 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,
+ QRect(size.width() - right, size.height() - bottom, right, bottom));
+ }
}
+
+} // namespace Utils
diff --git a/library/style/stylehelper.h b/library/style/stylehelper.h
index b261aa7..61c1e16 100644
--- a/library/style/stylehelper.h
+++ b/library/style/stylehelper.h
@@ -31,15 +31,20 @@
#define STYLEHELPER_H
#include <QtGui/QColor>
+#include <QtGui/QStyle>
QT_BEGIN_NAMESPACE
class QPalette;
class QPainter;
class QRect;
+// Note, this is exported but in a private header as qtopengl depends on it.
+// We should consider adding this as a public helper function.
+void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0);
QT_END_NAMESPACE
// Helper class holding all custom color values
+namespace Utils {
class StyleHelper
{
public:
@@ -49,6 +54,7 @@ public:
static QPalette sidebarFontPalette(const QPalette &original);
// This is our color table, all colors derive from baseColor
+ static QColor requestedBaseColor() { return m_requestedBaseColor; }
static QColor baseColor(bool lightColored = false);
static QColor panelTextColor(bool lightColored = false);
static QColor highlightColor(bool lightColored = false);
@@ -57,21 +63,31 @@ public:
static QColor buttonTextColor() { return QColor(0x4c4c4c); }
static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50);
+ static QColor sidebarHighlight() { 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
static void setBaseColor(const QColor &color);
+ // Draws a shaded anti-aliased arrow
+ static void drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option);
+
// Gradients used for panels
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 menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect);
-
- static void rectWithLeftLine(const QWidget *widget, QPainter *painter, const QRect &rect);
- static void drawSlider(QPainter *painter, const QRect &rect);
-
- // Pixmap cache should only be enabled for X11 due to slow gradients
static bool usePixmapCache() { return true; }
+ static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode,
+ int radius = 3, const QColor &color = QColor(0, 0, 0, 130),
+ const QPoint &offset = QPoint(1, -2));
+ static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
+ int left = 0, int top = 0, int right = 0, int bottom = 0);
+
private:
static QColor m_baseColor;
+ static QColor m_requestedBaseColor;
};
+
+} // namespace Utils
#endif // STYLEHELPER_H
diff --git a/library/toolbox.cpp b/library/toolbox.cpp
index 299da30..e0b69a2 100644
--- a/library/toolbox.cpp
+++ b/library/toolbox.cpp
@@ -41,6 +41,8 @@
#include <QtGui/QSpacerItem>
#include <QtGui/QScrollBar>
+using namespace Utils;
+
ToolBox::ToolBox(bool pagesOpenOnInsertion, QWidget *parent)
: QScrollArea(parent)
, mLayout(0)
diff --git a/library/toolbox.h b/library/toolbox.h
index 7303b0c..337e402 100644
--- a/library/toolbox.h
+++ b/library/toolbox.h
@@ -38,13 +38,15 @@
#include <QtCore/QList>
class ToolBoxPage;
-class StyledBar;
class OptionsItem;
class QToolButton;
class QFormLayout;
class QStringList;
class QVBoxLayout;
class QHBoxLayout;
+namespace Utils {
+ class StyledBar;
+}
class ToolBox : public QScrollArea
{
@@ -93,7 +95,7 @@ private:
QWidget *mPage;
QFormLayout *mInnerLayout;
QHBoxLayout *mHeaderLayout;
- StyledBar *mHeaderBar;
+ Utils::StyledBar *mHeaderBar;
QList<OptionsItem *> mOptions;
bool mAdvancedMode;
QStringList mLastFilters;