2
* Copyright (c) 2007 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "outputgraphicsitem.h"
20
#include "outputconfig.h"
26
#include <QGraphicsScene>
27
#include <KGlobalSettings>
29
OutputGraphicsItem::OutputGraphicsItem(OutputConfig *config)
30
: QGraphicsRectItem(config->rect())
33
m_left = m_right = m_top = m_bottom = NULL;
35
setPen(QPen(Qt::black));
37
setFlag(QGraphicsItem::ItemIsMovable, false);
38
// FIXME not implemented yet setFlag(QGraphicsItem::ItemIsSelectable, true);
40
m_text = new QGraphicsTextItem(QString(), this);
42
QFont font = KGlobalSettings::generalFont();
43
font.setPixelSize(72);
44
m_text->setFont(font);
46
m_text->setVisible( false );
49
OutputGraphicsItem::~OutputGraphicsItem()
54
void OutputGraphicsItem::configUpdated()
56
if( !m_config->isActive()) {
58
m_text->setVisible( false );
62
m_text->setVisible( true );
63
setRect( m_config->rect());
64
setBrush(QColor(0, 255, 0, 128));
65
// An example of this description text with radeonhd on randr 1.2:
67
// 1680x1050 (60.0 Hz)
68
QString refresh = QString::number(m_config->refreshRate(), 'f', 1);
69
QString desc = m_config->output()->name() + '\n' +
70
QString("%1x%2 (%3 Hz)").arg(rect().width()).arg(rect().height()).arg(refresh);
71
m_text->setPlainText( desc );
72
// more accurate text centering
73
QRectF textRect = m_text->boundingRect();
74
m_text->setPos( rect().x() + (rect().width() - textRect.width()) / 2,
75
rect().y() + (rect().height() - textRect.height()) / 2);
78
OutputGraphicsItem *OutputGraphicsItem::left() const
83
OutputGraphicsItem *OutputGraphicsItem::right() const
88
OutputGraphicsItem *OutputGraphicsItem::top() const
93
OutputGraphicsItem *OutputGraphicsItem::bottom() const
98
void OutputGraphicsItem::setTop(OutputGraphicsItem *output)
100
// if we already have that output at top, then just return
104
OutputGraphicsItem *oldTop = m_top;
107
// if we currently have a top item, set the given item as the bottom of our old item
109
oldTop->setBottom(output);
111
// check whether we have a left->top or a right->top to update the pointers
112
if (m_left && m_left->top())
114
OutputGraphicsItem *item = m_left->top();
116
qDebug("Oops, this should not happen");
117
item->setRight(output);
119
output->setLeft(item);
122
if (m_right && m_right->top())
124
OutputGraphicsItem *item = m_right->top();
126
qDebug("Oops, this should not happen");
127
item->setLeft(output);
129
output->setRight(item);
133
void OutputGraphicsItem::setBottom(OutputGraphicsItem *output)
135
// if we already have that output at bottom, just return
136
if (m_bottom == output)
139
OutputGraphicsItem *oldBottom = m_bottom;
142
// if we currently have a bottom item, set the given item as the top of our old item
144
oldBottom->setTop(output);
146
// check whether we have a left->bottom or a right->bottom to update the pointers
147
if (m_left && m_left->bottom())
149
OutputGraphicsItem *item = m_left->bottom();
151
qDebug("Oops, this should not happen");
152
item->setRight(output);
154
output->setLeft(item);
157
if (m_right && m_right->bottom())
159
OutputGraphicsItem *item = m_right->bottom();
161
qDebug("Oops, this should not happen");
162
item->setLeft(output);
164
output->setRight(item);
168
void OutputGraphicsItem::setLeft(OutputGraphicsItem *output)
170
// if we already have that output at left, then just return
171
if (m_left == output)
174
OutputGraphicsItem *oldLeft = m_left;
177
// if we currently have a left item, set the given item as the right of our old item
179
oldLeft->setRight(output);
181
// check whether we have a top->left or a bottom->left to update the pointers
182
if (m_top && m_top->left())
184
OutputGraphicsItem *item = m_top->left();
186
qDebug("Oops, this should not happen");
187
item->setBottom(output);
189
output->setTop(item);
192
if (m_bottom && m_bottom->left())
194
OutputGraphicsItem *item = m_bottom->left();
196
qDebug("Oops, this should not happen");
197
item->setTop(output);
199
output->setBottom(item);
203
void OutputGraphicsItem::setRight(OutputGraphicsItem *output)
205
// if we already have that output at right, then just return
206
if (m_right == output)
209
OutputGraphicsItem *oldRight = m_right;
212
// if we currently have a right item, set the given item as the left of our old item
214
oldRight->setLeft(output);
216
// check whether we have a top->right or a bottom->right to update the pointers
217
if (m_top && m_top->right())
219
OutputGraphicsItem *item = m_top->right();
221
qDebug("Oops, this should not happen");
222
item->setBottom(output);
224
output->setTop(item);
227
if (m_bottom && m_bottom->right())
229
OutputGraphicsItem *item = m_bottom->right();
231
qDebug("Oops, this should not happen");
232
item->setTop(output);
234
output->setBottom(item);
238
void OutputGraphicsItem::disconnect()
240
// for now just disconnect everything
243
m_top->m_bottom = NULL;
244
if (!m_top->isConnected())
245
emit itemChanged(m_top);
249
m_bottom->m_top = NULL;
250
if (!m_bottom->isConnected())
251
emit itemChanged(m_bottom);
255
m_left->m_right = NULL;
256
if (!m_left->isConnected())
257
emit itemChanged(m_left);
261
m_right->m_left = NULL;
262
if (!m_right->isConnected())
263
emit itemChanged(m_right);
266
m_top = m_bottom = m_left = m_right = NULL;
269
void OutputGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
271
// disconnect from the current layout
274
QGraphicsRectItem::mousePressEvent(event);
277
void OutputGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
279
QGraphicsRectItem::mouseReleaseEvent(event);
280
emit itemChanged(this);
283
bool OutputGraphicsItem::isConnected()
285
return (m_top != NULL || m_bottom != NULL || m_left != NULL || m_right != NULL);
288
#include "outputgraphicsitem.moc"