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
|
/**
* monitorworkspace.cpp
*
* Copyright (c) 2011 Timothy Pearson <[email protected]>
*
* 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.
*/
#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <unistd.h>
#include <string>
#include <stdio.h>
#include <tqstring.h>
#include "monitorworkspace.h"
using namespace std;
/**** Monitor Region ****/
MonitorRegion::MonitorRegion()
{
}
MonitorRegion::MonitorRegion(TQRect rect)
{
rectangles.resize(1);
rectangles[0] = rect;
}
MonitorRegion::MonitorRegion(TQMemArray<TQRect> newrects)
{
rectangles = newrects;
}
MonitorRegion::~MonitorRegion()
{
}
TQMemArray<TQRect> MonitorRegion::rects()
{
return rectangles;
}
MonitorRegion MonitorRegion::unite(MonitorRegion rect)
{
int i;
int j;
TQMemArray<TQRect> newrectangles = rectangles.copy(); // This MUST be a copy, otherwise Bad Things will happen VERY quickly!
newrectangles.resize(rectangles.count() + rect.rects().count());
j=0;
for (i=rectangles.count();i<newrectangles.count();i++) {
newrectangles[i] = rect.rects()[j];
j++;
}
MonitorRegion newregion(newrectangles);
return newregion;
}
bool MonitorRegion::contains(TQRect rect)
{
int i;
for (i=0;i<rectangles.count();i++) {
if (rectangles[i].intersects(rect))
return true;
}
return false;
}
/**** Draggable Monitor Widget ****/
DraggableMonitor::DraggableMonitor( TQWidget* parent, const char* name, int wflags )
: TQLabel( parent, name, wflags )
{
setAlignment(AlignHCenter | AlignVCenter);
setFrameShape(Box);
setFrameShadow(Plain);
setLineWidth(4);
setMidLineWidth(4);
}
DraggableMonitor::~DraggableMonitor()
{
}
void DraggableMonitor::mousePressEvent(TQMouseEvent *event)
{
lastMousePosition = event->pos();
emit(monitorSelected(screen_id));
}
void DraggableMonitor::mouseMoveEvent(TQMouseEvent *event)
{
TQPoint mousePos = event->pos();
TQPoint mouseMove = TQPoint(mousePos.x() - lastMousePosition.x(), mousePos.y() - lastMousePosition.y());
int moveToX = x()+mouseMove.x();
int moveToY = y()+mouseMove.y();
int maxX = parentWidget()->width() - width() - 1;
int maxY = parentWidget()->height() - height() - 1;
if (moveToX < 1) moveToX = 1;
if (moveToY < 1) moveToY = 1;
if (moveToX > maxX) moveToX = maxX;
if (moveToY > maxY) moveToY = maxY;
if (!is_primary)
move(moveToX, moveToY);
}
void DraggableMonitor::mouseReleaseEvent(TQMouseEvent *event)
{
emit(monitorDragComplete(screen_id));
}
/**** Draggable Monitor Container ****/
MonitorWorkspace::MonitorWorkspace( TQWidget* parent, const char* name )
: TQWorkspace( parent, name )
{
}
MonitorWorkspace::~MonitorWorkspace()
{
}
void MonitorWorkspace::resizeEvent( TQResizeEvent* re )
{
TQWorkspace::resizeEvent(re);
emit(workspaceRelayoutNeeded());
}
#include "monitorworkspace.moc"
|