summaryrefslogtreecommitdiffstats
path: root/src/gvcore/fullscreenbar.cpp
blob: 493dfd03e06d88592da3c3d0aae1057ff174540e (plain)
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
/*
Gwenview - A simple image viewer for TDE
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.

*/
// TQt
#include <tqbitmap.h>
#include <tqevent.h>
#include <tqlayout.h>
#include <tqpainter.h>
#include <tqtimer.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(TQPainter& painter, const TQRect& 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 {
	TQTimer mTimer;
	BarState mState;
	bool mFirstShow;
};


FullScreenBar::FullScreenBar(TQWidget* parent)
: TDEToolBar(parent, "FullScreenBar") {
	d=new Private;
	d->mState=OUT;
	d->mFirstShow=true;
	setIconSize(FULLSCREEN_ICON_SIZE);
	setMovingEnabled(false);

	TQColor bg=colorGroup().highlight();
	TQColor fg=colorGroup().highlightedText();
	TQPalette pal(palette());
	pal.setColor(TQColorGroup::Background, bg);
	pal.setColor(TQColorGroup::Foreground, fg);
	pal.setColor(TQColorGroup::Button, bg);
	pal.setColor(TQColorGroup::ButtonText, fg);
	setPalette(pal);
	
	// Timer
	connect(&d->mTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(slotUpdateSlide()) );
}


FullScreenBar::~FullScreenBar() {
	delete d;
}


void FullScreenBar::resizeEvent(TQResizeEvent* event) {
	TDEToolBar::resizeEvent(event);

	// Create a mask
	TQPainter painter;
	TQBitmap mask(size(), true);
	painter.begin(&mask);
	painter.setBrush(TQt::white);
	fillMask(painter, rect());
	painter.end();
	
	setMask(mask);
}


void FullScreenBar::showEvent(TQShowEvent* event) {
	TDEToolBar::showEvent(event);
	// Make sure the bar position corresponds to the OUT state
	if (!d->mFirstShow) return;
	d->mFirstShow=false;
	move(0, -height());
	layout()->setResizeMode(TQLayout::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