1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "styledbar.h"
27 
28 #include <QPainter>
29 #include <QStyleOption>
30 
31 using namespace Utils;
32 
StyledBar(QWidget * parent)33 StyledBar::StyledBar(QWidget *parent)
34     : QWidget(parent)
35 {
36     setProperty("panelwidget", true);
37     setProperty("panelwidget_singlerow", true);
38     setProperty("lightColored", false);
39 }
40 
setSingleRow(bool singleRow)41 void StyledBar::setSingleRow(bool singleRow)
42 {
43     setProperty("panelwidget_singlerow", singleRow);
44 }
45 
isSingleRow() const46 bool StyledBar::isSingleRow() const
47 {
48     return property("panelwidget_singlerow").toBool();
49 }
50 
setLightColored(bool lightColored)51 void StyledBar::setLightColored(bool lightColored)
52 {
53     if (isLightColored() == lightColored)
54         return;
55     setProperty("lightColored", lightColored);
56     const QList<QWidget *> children = findChildren<QWidget *>();
57     for (QWidget *childWidget : children)
58         childWidget->style()->polish(childWidget);
59 }
60 
isLightColored() const61 bool StyledBar::isLightColored() const
62 {
63     return property("lightColored").toBool();
64 }
65 
paintEvent(QPaintEvent * event)66 void StyledBar::paintEvent(QPaintEvent *event)
67 {
68     Q_UNUSED(event)
69     QPainter painter(this);
70     QStyleOptionToolBar option;
71     option.rect = rect();
72     option.state = QStyle::State_Horizontal;
73     style()->drawControl(QStyle::CE_ToolBar, &option, &painter, this);
74 }
75 
StyledSeparator(QWidget * parent)76 StyledSeparator::StyledSeparator(QWidget *parent)
77     : QWidget(parent)
78 {
79     setFixedWidth(10);
80 }
81 
paintEvent(QPaintEvent * event)82 void StyledSeparator::paintEvent(QPaintEvent *event)
83 {
84     Q_UNUSED(event)
85     QPainter painter(this);
86     QStyleOption option;
87     option.rect = rect();
88     option.state = QStyle::State_Horizontal;
89     option.palette = palette();
90     style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &option, &painter, this);
91 }
92