summaryrefslogtreecommitdiffstats
path: root/knights/tabgrip.cpp
blob: 563dd8f1191f44f34cc83f96963d745da86b64ef (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
/***************************************************************************
                          tabgrip.cpp  -  description
                             -------------------
    begin                : Fri Sep 13 2002
    copyright            : (C) 2003 by Troy Corbin Jr.
    email                : tcorbin@users.sf.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "tabgrip.moc"
#include "resource.h"
#include <qpainter.h>

TabGrip::TabGrip(QWidget *parent, const char *name ) : QWidget(parent,name)
{
	setMaximumSize( 3200, 12 );
	setMinimumSize( 32, 12 );

	isDragging = FALSE;
	couldDrag = FALSE;

	setCursor( Qt::SizeAllCursor );

	show();
}
TabGrip::~TabGrip()
{
}
///////////////////////////////////////
//
//	TabGrip::paintEvent
//
///////////////////////////////////////
void TabGrip::paintEvent( QPaintEvent* )
{
	QPainter paint( this );
	QColorGroup group( colorGroup() );
	paint.setPen( group.light() );
	paint.drawLine( 2, 2, width() - 3, 2 );
	paint.drawLine( 2, 5, width() - 3, 5 );
	paint.drawLine( 2, 8, width() - 3, 8 );
	paint.setPen( group.dark() );
	paint.drawLine( 2, 3, width() - 3, 3 );
	paint.drawLine( 2, 6, width() - 3, 6 );
	paint.drawLine( 2, 9, width() - 3, 9 );
}
///////////////////////////////////////
//
//	TabGrip::mousePressEvent
//
///////////////////////////////////////
void TabGrip::mousePressEvent( QMouseEvent *event )
{
	event->accept();
	if(event->button() == Qt::LeftButton)
	{
		couldDrag = TRUE;
		offset = mapToGlobal( event->pos() );
		offset.setX( topLevelWidget()->x() - offset.x() );
		offset.setY( topLevelWidget()->y() - offset.y() );
	}
}
///////////////////////////////////////
//
//	TabGrip::mouseMoveEvent
//
///////////////////////////////////////
void TabGrip::mouseMoveEvent( QMouseEvent *event )
{
	/*
		By default, MouseMoveEvent is never called unless the user has
		a button held down, so this should only be called if we're dragging.
	*/
	event->accept();
	if( couldDrag == TRUE )
	{
		/* Dragging Page */
		isDragging = TRUE;
		couldDrag = FALSE;
		QApplication::setOverrideCursor( Qt::SizeAllCursor );
	}
}
///////////////////////////////////////
//
//	TabGrip::mouseReleaseEvent
//
///////////////////////////////////////
void TabGrip::mouseReleaseEvent( QMouseEvent *event )
{
	event->accept();
	if(event->button() == Qt::LeftButton)
	{
		couldDrag = FALSE;
		if( isDragging )
		{
			QApplication::restoreOverrideCursor();
			isDragging = FALSE;
			emit wasDragged( event->globalPos(), offset );
		}
	}
}