ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
graphics
VP1
VP1Base
src
VP1TabBar.cxx
Go to the documentation of this file.
1
2
// //
3
// File adopted from KDE4 libraries by //
4
// T. Kittelmann <Thomas.Kittelmann@cern.ch>, March 2007. //
5
// //
6
// Main thing is to remove dependence on KDE for length of title text //
7
// settings, delay on drag settings and title eliding. Also, //
8
// hoverbuttons were removed (since these had not been properly //
9
// implemented in KDE4 at the time the code was copied). //
10
// //
11
// Notice about Copyrights and GPL license from the orignal file is //
12
// left untouched below. //
13
// //
15
16
/* This file is part of the KDE libraries
17
Copyright (C) 2003 Stephan Binner <binner@kde.org>
18
Copyright (C) 2003 Zack Rusin <zack@kde.org>
19
20
This library is free software; you can redistribute it and/or
21
modify it under the terms of the GNU Library General Public
22
License as published by the Free Software Foundation; either
23
version 2 of the License, or (at your option) any later version.
24
25
This library is distributed in the hope that it will be useful,
26
but WITHOUT ANY WARRANTY; without even the implied warranty of
27
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
Library General Public License for more details.
29
30
You should have received a copy of the GNU Library General Public License
31
along with this library; see the file COPYING.LIB. If not, write to
32
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
33
Boston, MA 02110-1301, USA.
34
*/
35
36
#include <QTimer>
37
#include <QApplication>
38
#include <QMouseEvent>
39
40
#include "
VP1Base/VP1TabBar.h
"
41
42
class
VP1TabBar::Private
43
{
44
public
:
45
Private
()
46
:
mReorderStartTab
( -1 ),
47
mReorderPreviousTab
( -1 ),
48
mDragSwitchTab
( -1 ),
49
mActivateDragSwitchTabTimer
(0),
50
mTabReorderingEnabled
( false ),
51
mTabCloseActivatePrevious
( false )
52
{
53
}
54
55
QPoint
mDragStart
;
56
int
mReorderStartTab
;
57
int
mReorderPreviousTab
;
58
int
mDragSwitchTab
;
59
QTimer *
mActivateDragSwitchTabTimer
;
60
61
bool
mTabReorderingEnabled
;
62
bool
mTabCloseActivatePrevious
;
63
64
};
65
66
VP1TabBar::VP1TabBar
( QWidget *parent )
67
: QTabBar( parent ),
68
m_d
( new
Private
)
69
{
70
setAcceptDrops(
true
);
71
setMouseTracking(
true
);
72
73
//m_d->mEnableCloseButtonTimer = new QTimer( this );
74
//connect( m_d->mEnableCloseButtonTimer, SIGNAL( timeout() ), SLOT( enableCloseButton() ) );
75
76
m_d
->mActivateDragSwitchTabTimer =
new
QTimer(
this
);
77
m_d
->mActivateDragSwitchTabTimer->setSingleShot(
true
);
78
connect(
m_d
->mActivateDragSwitchTabTimer, &QTimer::timeout ,
this
, &
VP1TabBar::activateDragSwitchTab
);
79
80
//connect( this, SIGNAL( layoutChanged() ), SLOT( onLayoutChange() ) );
81
}
82
83
VP1TabBar::~VP1TabBar
()
84
{
85
delete
m_d
;
86
}
87
88
void
VP1TabBar::mouseDoubleClickEvent
( QMouseEvent *event )
89
{
90
if
( event->button() != Qt::LeftButton )
91
return
;
92
93
int
tab =
selectTab
( event->pos() );
94
if
( tab != -1 ) {
95
emit
mouseDoubleClick
( tab );
96
return
;
97
}
98
99
QTabBar::mouseDoubleClickEvent( event );
100
}
101
102
void
VP1TabBar::mousePressEvent
( QMouseEvent *event )
103
{
104
if
( event->button() == Qt::LeftButton ) {
105
//m_d->mEnableCloseButtonTimer->stop();
106
m_d
->mDragStart =
event
->pos();
107
}
else
if
( event->button() == Qt::RightButton ) {
108
int
tab =
selectTab
( event->pos() );
109
if
( tab != -1 ) {
110
emit
contextMenu
( tab, mapToGlobal( event->pos() ) );
111
return
;
112
}
113
}
114
115
QTabBar::mousePressEvent( event );
116
}
117
118
void
VP1TabBar::mouseMoveEvent
( QMouseEvent *event )
119
{
120
if
( event->buttons() == Qt::LeftButton ) {
121
int
tab =
selectTab
( event->pos() );
122
if
(
m_d
->mDragSwitchTab && tab !=
m_d
->mDragSwitchTab ) {
123
m_d
->mActivateDragSwitchTabTimer->stop();
124
m_d
->mDragSwitchTab = 0;
125
}
126
127
int
delay
= 5;
//TK fixme KGlobalSettings::dndEventDelay();
128
QPoint newPos =
event
->pos();
129
if
( newPos.x() >
m_d
->mDragStart.x() +
delay
|| newPos.x() <
m_d
->mDragStart.x() -
delay
||
130
newPos.y() >
m_d
->mDragStart.y() +
delay
|| newPos.y() <
m_d
->mDragStart.y() -
delay
) {
131
if
( tab != -1 ) {
132
emit
initiateDrag
( tab );
133
return
;
134
}
135
}
136
}
else
if
( event->buttons() == Qt::MiddleButton ) {
137
if
(
m_d
->mReorderStartTab == -1 ) {
138
int
delay
= 5;
//TK fixme KGlobalSettings::dndEventDelay();
139
QPoint newPos =
event
->pos();
140
141
if
( newPos.x() >
m_d
->mDragStart.x() +
delay
|| newPos.x() <
m_d
->mDragStart.x() -
delay
||
142
newPos.y() >
m_d
->mDragStart.y() +
delay
|| newPos.y() <
m_d
->mDragStart.y() -
delay
) {
143
int
tab =
selectTab
( event->pos() );
144
if
( tab != -1 &&
m_d
->mTabReorderingEnabled ) {
145
m_d
->mReorderStartTab = tab;
146
grabMouse( Qt::SizeAllCursor );
147
return
;
148
}
149
}
150
}
else
{
151
int
tab =
selectTab
( event->pos() );
152
if
( tab != -1 ) {
153
int
reorderStopTab = tab;
154
if
(
m_d
->mReorderStartTab != reorderStopTab &&
m_d
->mReorderPreviousTab != reorderStopTab ) {
155
emit
moveTab
(
m_d
->mReorderStartTab, reorderStopTab );
156
157
m_d
->mReorderPreviousTab =
m_d
->mReorderStartTab;
158
m_d
->mReorderStartTab = reorderStopTab;
159
160
return
;
161
}
162
}
163
}
164
}
165
166
QTabBar::mouseMoveEvent( event );
167
}
168
169
170
void
VP1TabBar::activateDragSwitchTab
()
171
{
172
int
tab =
selectTab
( mapFromGlobal( QCursor::pos() ) );
173
if
( tab != -1 &&
m_d
->mDragSwitchTab == tab )
174
setCurrentIndex(
m_d
->mDragSwitchTab );
175
176
m_d
->mDragSwitchTab = 0;
177
}
178
179
void
VP1TabBar::mouseReleaseEvent
( QMouseEvent *event )
180
{
181
if
( event->button() == Qt::MiddleButton ) {
182
if
(
m_d
->mReorderStartTab == -1 ) {
183
int
tab =
selectTab
( event->pos() );
184
if
( tab != -1 ) {
185
emit
mouseMiddleClick
( tab );
186
return
;
187
}
188
}
else
{
189
releaseMouse();
190
setCursor( Qt::ArrowCursor );
191
m_d
->mReorderStartTab = -1;
192
m_d
->mReorderPreviousTab = -1;
193
}
194
}
195
196
QTabBar::mouseReleaseEvent( event );
197
}
198
199
void
VP1TabBar::dragEnterEvent
( QDragEnterEvent *event )
200
{
201
event
->setAccepted(
true
);
202
QTabBar::dragEnterEvent( event );
203
}
204
205
void
VP1TabBar::dragMoveEvent
( QDragMoveEvent *event )
206
{
207
int
tab =
selectTab
( event->pos() );
208
if
( tab != -1 ) {
209
bool
accept =
false
;
210
// The receivers of the testCanDecode() signal has to adjust
211
// 'accept' accordingly.
212
emit
testCanDecode
( event, accept );
213
if
( accept && tab != currentIndex() ) {
214
m_d
->mDragSwitchTab = tab;
215
m_d
->mActivateDragSwitchTabTimer->start( QApplication::doubleClickInterval() * 2 );
216
}
217
218
event
->setAccepted( accept );
219
return
;
220
}
221
222
event
->setAccepted(
false
);
223
QTabBar::dragMoveEvent( event );
224
}
225
226
void
VP1TabBar::dropEvent
( QDropEvent *event )
227
{
228
int
tab =
selectTab
( event->pos() );
229
if
( tab != -1 ) {
230
m_d
->mActivateDragSwitchTabTimer->stop();
231
m_d
->mDragSwitchTab = 0;
232
emit
receivedDropEvent
( tab , event );
233
return
;
234
}
235
236
QTabBar::dropEvent( event );
237
}
238
239
#ifndef QT_NO_WHEELEVENT
240
void
VP1TabBar::wheelEvent
( QWheelEvent *event )
241
{
242
emit(
wheelDelta
( event->angleDelta().y() ) );
243
}
244
#endif
245
246
bool
VP1TabBar::isTabReorderingEnabled
()
const
247
{
248
return
m_d
->mTabReorderingEnabled;
249
}
250
251
void
VP1TabBar::setTabReorderingEnabled
(
bool
on )
252
{
253
m_d
->mTabReorderingEnabled = on;
254
}
255
256
bool
VP1TabBar::tabCloseActivatePrevious
()
const
257
{
258
return
m_d
->mTabCloseActivatePrevious;
259
}
260
261
void
VP1TabBar::setTabCloseActivatePrevious
(
bool
on )
262
{
263
m_d
->mTabCloseActivatePrevious = on;
264
}
265
266
267
void
VP1TabBar::tabLayoutChange
()
268
{
269
m_d
->mActivateDragSwitchTabTimer->stop();
270
m_d
->mDragSwitchTab = 0;
271
}
272
273
int
VP1TabBar::selectTab
(
const
QPoint &pos )
const
274
{
275
for
(
int
i = 0; i <
count
(); ++i )
276
if
( tabRect( i ).
contains
( pos ) )
277
return
i;
278
279
return
-1;
280
}
281
delay
double delay(std::size_t d)
Definition
JetTrigTimerTest.cxx:11
VP1TabBar.h
VP1TabBar::Private
Definition
VP1TabBar.cxx:43
VP1TabBar::Private::Private
Private()
Definition
VP1TabBar.cxx:45
VP1TabBar::Private::mReorderStartTab
int mReorderStartTab
Definition
VP1TabBar.cxx:56
VP1TabBar::Private::mReorderPreviousTab
int mReorderPreviousTab
Definition
VP1TabBar.cxx:57
VP1TabBar::Private::mTabCloseActivatePrevious
bool mTabCloseActivatePrevious
Definition
VP1TabBar.cxx:62
VP1TabBar::Private::mDragSwitchTab
int mDragSwitchTab
Definition
VP1TabBar.cxx:58
VP1TabBar::Private::mDragStart
QPoint mDragStart
Definition
VP1TabBar.cxx:55
VP1TabBar::Private::mTabReorderingEnabled
bool mTabReorderingEnabled
Definition
VP1TabBar.cxx:61
VP1TabBar::Private::mActivateDragSwitchTabTimer
QTimer * mActivateDragSwitchTabTimer
Definition
VP1TabBar.cxx:59
VP1TabBar::mouseMiddleClick
void mouseMiddleClick(int)
VP1TabBar::tabLayoutChange
virtual void tabLayoutChange()
Definition
VP1TabBar.cxx:267
VP1TabBar::dragMoveEvent
virtual void dragMoveEvent(QDragMoveEvent *event)
Definition
VP1TabBar.cxx:205
VP1TabBar::isTabReorderingEnabled
bool isTabReorderingEnabled() const
Definition
VP1TabBar.cxx:246
VP1TabBar::mouseDoubleClick
void mouseDoubleClick(int)
VP1TabBar::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *event)
Definition
VP1TabBar.cxx:179
VP1TabBar::dropEvent
virtual void dropEvent(QDropEvent *event)
Definition
VP1TabBar.cxx:226
VP1TabBar::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event)
Definition
VP1TabBar.cxx:118
VP1TabBar::testCanDecode
void testCanDecode(const QDragMoveEvent *, bool &)
VP1TabBar::setTabCloseActivatePrevious
void setTabCloseActivatePrevious(bool)
Definition
VP1TabBar.cxx:261
VP1TabBar::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event)
Definition
VP1TabBar.cxx:102
VP1TabBar::activateDragSwitchTab
virtual void activateDragSwitchTab()
Definition
VP1TabBar.cxx:170
VP1TabBar::m_d
Private *const m_d
Definition
VP1TabBar.h:94
VP1TabBar::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *event)
Definition
VP1TabBar.cxx:199
VP1TabBar::~VP1TabBar
virtual ~VP1TabBar()
Definition
VP1TabBar.cxx:83
VP1TabBar::moveTab
void moveTab(int, int)
VP1TabBar::tabCloseActivatePrevious
bool tabCloseActivatePrevious() const
Definition
VP1TabBar.cxx:256
VP1TabBar::mouseDoubleClickEvent
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Definition
VP1TabBar.cxx:88
VP1TabBar::wheelEvent
virtual void wheelEvent(QWheelEvent *event)
Definition
VP1TabBar.cxx:240
VP1TabBar::wheelDelta
void wheelDelta(int)
VP1TabBar::contextMenu
void contextMenu(int, const QPoint &)
VP1TabBar::initiateDrag
void initiateDrag(int)
VP1TabBar::receivedDropEvent
void receivedDropEvent(int, QDropEvent *)
VP1TabBar::VP1TabBar
VP1TabBar(QWidget *parent=0)
Definition
VP1TabBar.cxx:66
VP1TabBar::setTabReorderingEnabled
void setTabReorderingEnabled(bool enable)
Definition
VP1TabBar.cxx:251
VP1TabBar::selectTab
int selectTab(const QPoint &position) const
Definition
VP1TabBar.cxx:273
contains
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Definition
hcg.cxx:116
count
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Definition
hcg.cxx:148
Generated on
for ATLAS Offline Software by
1.17.0