1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
// vim:set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview - A simple image viewer for KDE
Copyright 2000-2004 Aur�ien G�eau
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// Qt
#include <qbitmap.h>
#include <qevent.h>
#include <qlayout.h>
#include <qpainter.h>
#include <qtimer.h>
// KDE
#include <kdebug.h>
// Local
#include "fullscreenbar.moc"
namespace Gwenview {
const int FULLSCREEN_ICON_SIZE = 32;
const int FULLSCREEN_LABEL_RADIUS = 6;
// Intervals are in milliseconds
const int SLIDE_IN_INTERVAL = 4;
const int SLIDE_OUT_INTERVAL = 12;
// Step is in pixels
const int SLIDE_STEP = 4;
static void fillMask(QPainter& painter, const QRect& rect) {
painter.fillRect(
rect.left(),
rect.top(),
rect.width() - FULLSCREEN_LABEL_RADIUS,
rect.height(),
painter.brush());
painter.fillRect(
rect.right() - FULLSCREEN_LABEL_RADIUS + 1,
rect.top(),
FULLSCREEN_LABEL_RADIUS,
rect.height() - FULLSCREEN_LABEL_RADIUS,
painter.brush());
painter.drawPie(
rect.right() - 2*FULLSCREEN_LABEL_RADIUS + 1,
rect.bottom() - 2*FULLSCREEN_LABEL_RADIUS + 1,
FULLSCREEN_LABEL_RADIUS*2, FULLSCREEN_LABEL_RADIUS*2,
0, -16*90);
}
enum BarState { OUT, SLIDING_OUT, SLIDING_IN, IN };
struct FullScreenBar::Private {
QTimer mTimer;
BarState mState;
bool mFirstShow;
};
FullScreenBar::FullScreenBar(QWidget* parent)
: KToolBar(parent, "FullScreenBar") {
d=new Private;
d->mState=OUT;
d->mFirstShow=true;
setIconSize(FULLSCREEN_ICON_SIZE);
setMovingEnabled(false);
QColor bg=colorGroup().highlight();
QColor fg=colorGroup().highlightedText();
QPalette pal(palette());
pal.setColor(QColorGroup::Background, bg);
pal.setColor(QColorGroup::Foreground, fg);
pal.setColor(QColorGroup::Button, bg);
pal.setColor(QColorGroup::ButtonText, fg);
setPalette(pal);
// Timer
connect(&d->mTimer, SIGNAL(timeout()), this, SLOT(slotUpdateSlide()) );
}
FullScreenBar::~FullScreenBar() {
delete d;
}
void FullScreenBar::resizeEvent(QResizeEvent* event) {
KToolBar::resizeEvent(event);
// Create a mask
QPainter painter;
QBitmap mask(size(), true);
painter.begin(&mask);
painter.setBrush(Qt::white);
fillMask(painter, rect());
painter.end();
setMask(mask);
}
void FullScreenBar::showEvent(QShowEvent* event) {
KToolBar::showEvent(event);
// Make sure the bar position corresponds to the OUT state
if (!d->mFirstShow) return;
d->mFirstShow=false;
move(0, -height());
layout()->setResizeMode(QLayout::Fixed);
}
void FullScreenBar::slideIn() {
if (d->mState!=IN) {
d->mState=SLIDING_IN;
d->mTimer.start(SLIDE_IN_INTERVAL);
}
}
void FullScreenBar::slideOut() {
if (d->mState!=OUT) {
d->mState=SLIDING_OUT;
d->mTimer.start(SLIDE_OUT_INTERVAL);
}
}
void FullScreenBar::slotUpdateSlide() {
int pos=y();
switch (d->mState) {
case SLIDING_OUT:
pos-=SLIDE_STEP;
if (pos<=-height()) {
d->mState=OUT;
d->mTimer.stop();
}
break;
case SLIDING_IN:
pos+=SLIDE_STEP;
if (pos>=0) {
pos=0;
d->mState=IN;
d->mTimer.stop();
}
break;
default:
kdWarning() << k_funcinfo << "We should not get there\n";
}
move(0, pos);
}
} // namespace
|