1 /* Copyright (c) 2015  Gerald Knizia
2  *
3  * This file is part of the IboView program (see: http://www.iboview.org)
4  *
5  * IboView is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, version 3.
8  *
9  * IboView is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with bfint (LICENSE). If not, see http://www.gnu.org/licenses/
16  *
17  * Please see IboView documentation in README.txt for:
18  * -- A list of included external software and their licenses. The included
19  *    external software's copyright is not touched by this agreement.
20  * -- Notes on re-distribution and contributions to/further development of
21  *    the IboView software
22  */
23 
24 #include <QApplication>
25 #include <QStyle>
26 #include <QSizeGrip>
27 #include "IvStatusBar.h"
28 #include <QLayout>
29 #include <QHBoxLayout>
30 #include <QSizePolicy>
31 #include <QEventLoop>
32 
33 // QColor GetStatusColor(FStatusClass Class)
34 // {
35 //    // these are some pure colors from http://www.w3schools.com/tags/ref_colorpicker.asp
36 //    switch (Class) {
37 //       case STATUS_Idle: return QRgb(0x0066CC);
38 //       case STATUS_Working: return QRgb(0x009900);
39 //       case STATUS_WorkingBg: return QRgb(0x003300);
40 //       case STATUS_Warning: return QRgb(0xFF9900);
41 //       case STATUS_Error: return QRgb(0xCC0000);
42 //       default: return QRgb(0x000000);
43 //    }
44 // }
45 
GetStatusStyle(FStatusClass Class)46 QString GetStatusStyle(FStatusClass Class)
47 {
48    // these are some pure colors from http://www.w3schools.com/tags/ref_colorpicker.asp
49    // hm... maybe I take the android default colors? http://developer.android.com/design/style/color.html
50    //   seems to be really close to what I chose. Wow, I have style 8).
51 //    font-weight: normal;
52 #define BGSTYLE(a) "color: #ffffff; background: " a
53    switch (Class) {
54       case STATUS_Idle: return BGSTYLE("#0066CC");
55 //       case STATUS_Working: return BGSTYLE("#009900");
56 //       case STATUS_WorkingBg: return BGSTYLE("#003300");
57 //       case STATUS_Warning: return BGSTYLE("#ff9900");
58 //       case STATUS_Error: return BGSTYLE("#cc0000");
59 //       default: return BGSTYLE("#000000");
60 //       case STATUS_Idle: return BGSTYLE("#0099CC"); // bright: 33b5e5
61       case STATUS_Working: return BGSTYLE("#669900");// bright: 99cc00
62       case STATUS_WorkingBg: return BGSTYLE("#003300");
63       case STATUS_Warning: return BGSTYLE("#ff8800"); // bright: ffbb33
64       case STATUS_Error: return BGSTYLE("#cc0000");
65       case STATUS_Confused:
66       default: return BGSTYLE("#9933cc"); // bright: aa66cc
67    }
68 #undef BGSTYLE
69 }
70 
GetStatusStyle1(FStatusClass Class)71 QString GetStatusStyle1(FStatusClass Class)
72 {
73    return QString("FStatusBar{margin: -10px; %1}").arg(GetStatusStyle(Class));
74 //    // these are some pure colors from http://www.w3schools.com/tags/ref_colorpicker.asp
75 //    // hm... maybe I take the android default colors? http://developer.android.com/design/style/color.html
76 //    //   seems to be really close to what I chose. Wow, I have style 8).
77 // #define BGSTYLE(a) "FStatusBar{margin: -10px; color: #ffffff; font-weight: normal; background: " a "}"
78 //    switch (Class) {
79 //       case STATUS_Idle: return BGSTYLE("#0066CC");
80 // //       case STATUS_Working: return BGSTYLE("#009900");
81 // //       case STATUS_WorkingBg: return BGSTYLE("#003300");
82 // //       case STATUS_Warning: return BGSTYLE("#ff9900");
83 // //       case STATUS_Error: return BGSTYLE("#cc0000");
84 // //       default: return BGSTYLE("#000000");
85 // //       case STATUS_Idle: return BGSTYLE("#0099CC"); // bright: 33b5e5
86 //       case STATUS_Working: return BGSTYLE("#669900");// bright: 99cc00
87 //       case STATUS_WorkingBg: return BGSTYLE("#003300");
88 //       case STATUS_Warning: return BGSTYLE("#ff8800"); // bright: ffbb33
89 //       case STATUS_Error: return BGSTYLE("#cc0000");
90 //       case STATUS_Confused:
91 //       default: return BGSTYLE("#9933cc"); // bright: aa66cc
92 //    }
93 // //    switch (Class) {
94 // //       case STATUS_Idle: return "QStatusBar{color: #ffffff; background: #0066CC}";
95 // //       case STATUS_Working: return "QStatusBar{color: #ffffff; background: #009900}";
96 // //       case STATUS_WorkingBg: return "QStatusBar{color: #ffffff; background: #003300}";
97 // //       case STATUS_Warning: return "QStatusBar{color: #ffffff; background: #ff9900}";
98 // //       case STATUS_Error: return "QStatusBar{color: #ffffff; background: #cc0000}";
99 // //       default: return "QStatusBar{color: #ffffff; background: #000000}";
100 // //    }
101 }
102 
103 
FStatusBar(QWidget * parent)104 FStatusBar::FStatusBar(QWidget *parent)
105    : FBase(parent), m_LastStatus(STATUS_Unknown)
106 {
107    // hm... problem: since we use style sheets, all the palette stuff
108    // is ignored, since the inherited cascading style sheet gets preference.
109    // Setting an empty style sheet does not help.
110    // It seems that the only way to change the appearance of a styled widget is
111    // to set a new style sheet. Maybe that is the wrong approach altogether, and
112    // I should use a graphicsView object? or make an own paint function? (might
113    // need that for the progress indicators anyway...)
114 //    setStyleSheet(GetStatusStyle(STATUS_Working));
115 //    layout()->setContentsMargins(0,-4,0,-6);
116 
117    QHBoxLayout *pLayout = new QHBoxLayout;
118    // hm.. something is off. Is there something which sets negative margins?
119    pLayout->setContentsMargins(15,0,15,0);
120 
121    m_pStatusText = new QLabel(this);
122    pLayout->addWidget(m_pStatusText);
123    pLayout->addWidget(new QSizeGrip(this));
124    setLayout(pLayout);
125 //    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
126 
127    SetStatus(STATUS_Working, "Starting");
128 }
129 
SetStatus(FStatusClass Class,QString Text)130 void FStatusBar::SetStatus(FStatusClass Class, QString Text)
131 {
132 //    QPalette palette = this->palette();
133 //    palette.setColor( this->foregroundRole(), Qt::white );
134 //    palette.setColor( this->backgroundRole(), QColor(0xf33333) );
135 //    palette.setColor( QPalette::Background, QColor(0xf3ff33) );
136 //    palette.setColor( QPalette::Window, QColor(0xf3fff3) );
137 //    this->setPalette(palette);
138 //    this->setAutoFillBackground(true);
139 
140    if (m_LastStatus != Class) {
141       setStyleSheet(GetStatusStyle1(Class));
142       m_LastStatus = Class;
143    }
144 //    showMessage(Text);
145    m_pStatusText->setText(Text);
146 //    if (Class == STATUS_Working) {
147 //       for (int iDummy = 0; iDummy < 100; ++ iDummy)
148 //          QCoreApplication::processEvents();
149 //          QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
150 //       // FIXME: ^- this is a REAALLLY bad idea. Could lead to re-entrant calls
151 //       // of all kinds of functions which are not expecting this.
152 //    }
153 }
154 
155 // void FStatusBar::Finished()
156 // {
157 //    SetStatus(STATUS_Idle, "Ready");
158 // }
159