3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "qsetborder.h"
19 #include <QMouseEvent>
20 #include <QPaintEvent>
23 QSetBorder::QSetBorder(QWidget * parent, char const * name, Qt::WFlags fl)
24 : QWidget(parent, name, fl), buffer(75, 75)
26 /* length of corner line */
27 l = buffer.width() / 10;
29 m = buffer.height() / 10;
41 void QSetBorder::paintEvent(QPaintEvent * e)
43 QWidget::paintEvent(e);
44 QPainter painter(this);
45 painter.drawPixmap(0, 0, buffer);
49 void QSetBorder::init()
52 QPainter paint(&buffer);
54 paint.setPen(Qt::black);
56 // FIXME: wow, readable !! :)
58 paint.drawLine(m + l , m, m + l, m + l);
59 paint.drawLine(w - (m + l), m, w - (m + l), m + l);
61 paint.drawLine(m, m + l , m + l, m + l);
62 paint.drawLine(m, h - (m + l), m + l, h - (m + l));
64 paint.drawLine(m + l ,h - m, m + l ,h - (m + l));
65 paint.drawLine(w - (m + l), h - m, w - (m + l), h - (m + l));
67 paint.drawLine(h - m, m+l, h - (m + l), m + l);
68 paint.drawLine(h - m, h - (m + l), h - (m + l),h - (m + l));
72 void QSetBorder::mousePressEvent(QMouseEvent * e)
74 if (e->y() > e->x()) {
75 if (e->y() < height() - e->x()) {
82 if (bottom_.enabled) {
83 setBottom(!bottom_.set);
85 bottomSet(bottom_.set);
89 if (e->y() < height() - e->x()) {
97 setRight(!right_.set);
109 void QSetBorder::drawLine(QColor const & col, int x, int y, int x2, int y2)
111 QPainter paint(&buffer);
112 QPen p = paint.pen();
116 paint.drawLine(x, y, x2, y2);
120 void QSetBorder::drawLeft(bool draw)
122 QColor col(draw ? Qt::black : Qt::white);
124 col = QColor("grey");
125 drawLine(col, m + l, m + l + 2, m + l, h - m - l - 1);
129 void QSetBorder::drawRight(bool draw)
131 QColor col(draw ? Qt::black : Qt::white);
133 col = QColor("grey");
134 drawLine(col, h - m - l + 1, m + l + 2, h - m - l + 1, h - m - l - 1);
138 void QSetBorder::drawTop(bool draw)
140 QColor col(draw ? Qt::black : Qt::white);
142 col = QColor("grey");
143 drawLine(col, m + l + 2, m + l, w - m - l - 1, m + l);
147 void QSetBorder::drawBottom(bool draw)
149 QColor col(draw ? Qt::black : Qt::white);
150 if (!bottom_.enabled)
151 col = QColor("grey");
152 drawLine(col, m + l + 2, w - m - l + 1, w - m - l - 1, w - m - l + 1);
156 void QSetBorder::setLeftEnabled(bool border)
158 left_.enabled = border;
163 void QSetBorder::setRightEnabled(bool border)
165 right_.enabled = border;
170 void QSetBorder::setTopEnabled(bool border)
172 top_.enabled = border;
177 void QSetBorder::setBottomEnabled(bool border)
179 bottom_.enabled = border;
184 void QSetBorder::setLeft(bool border)
191 void QSetBorder::setRight(bool border)
198 void QSetBorder::setTop(bool border)
205 void QSetBorder::setBottom(bool border)
207 bottom_.set = border;
212 void QSetBorder::setAll(bool border)
221 bool QSetBorder::getLeft()
227 bool QSetBorder::getRight()
233 bool QSetBorder::getTop()
239 bool QSetBorder::getBottom()
244 #include "qsetborder_moc.cpp"