2002-11-08 00:09:00 +00:00
|
|
|
/**
|
2003-03-14 00:20:42 +00:00
|
|
|
* \file qsetborder.C
|
2002-11-08 00:09:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
2002-11-28 18:07:39 +00:00
|
|
|
* \author John Levon
|
2002-11-08 00:09:00 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-11-08 00:09:00 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
#include <qpainter.h>
|
|
|
|
#include "qsetborder.h"
|
|
|
|
|
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
QSetBorder::QSetBorder(QWidget * parent, char const * name, WFlags fl)
|
2002-11-28 18:07:39 +00:00
|
|
|
: QWidget(parent, name, fl), buffer(75, 75)
|
2002-11-08 00:09:00 +00:00
|
|
|
{
|
|
|
|
/* length of corner line */
|
2002-11-15 05:44:14 +00:00
|
|
|
l = buffer.width() / 10;
|
2002-11-08 00:09:00 +00:00
|
|
|
/* margin */
|
2002-11-15 05:44:14 +00:00
|
|
|
m = buffer.height() / 10;
|
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
w = buffer.width();
|
|
|
|
h = buffer.height();
|
|
|
|
|
|
|
|
init();
|
2002-11-15 05:44:14 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
setMinimumSize(w,h);
|
|
|
|
setMaximumSize(w,h);
|
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
void QSetBorder::paintEvent(QPaintEvent * e)
|
2002-11-08 00:09:00 +00:00
|
|
|
{
|
2002-11-15 05:44:14 +00:00
|
|
|
QWidget::paintEvent(e);
|
|
|
|
bitBlt(this, 0, 0, &buffer, 0, 0, width(), height());
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
void QSetBorder::init()
|
|
|
|
{
|
|
|
|
buffer.fill();
|
|
|
|
QPainter paint;
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.begin(&buffer);
|
|
|
|
paint.setPen(Qt::black);
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-27 20:23:53 +00:00
|
|
|
// FIXME: wow, readable !! :)
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.drawLine(m + l , m, m + l, m + l);
|
|
|
|
paint.drawLine(w - (m + l), m, w - (m + l), m + l);
|
2002-11-08 00:09:00 +00:00
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.drawLine(m, m + l , m + l, m + l);
|
|
|
|
paint.drawLine(m, h - (m + l), m + l, h - (m + l));
|
2002-11-08 00:09:00 +00:00
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.drawLine(m + l ,h - m, m + l ,h - (m + l));
|
|
|
|
paint.drawLine(w - (m + l), h - m, w - (m + l), h - (m + l));
|
2002-11-08 00:09:00 +00:00
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.drawLine(h - m, m+l, h - (m + l), m + l);
|
|
|
|
paint.drawLine(h - m, h - (m + l), h - (m + l),h - (m + l));
|
2002-11-08 00:09:00 +00:00
|
|
|
|
|
|
|
paint.end();
|
|
|
|
}
|
2002-11-15 05:44:14 +00:00
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
void QSetBorder::mousePressEvent(QMouseEvent * e)
|
2002-11-08 00:09:00 +00:00
|
|
|
{
|
2002-11-15 05:44:14 +00:00
|
|
|
if (e->y() > e->x()) {
|
|
|
|
if (e->y() < height() - e->x()) {
|
2002-11-28 18:07:39 +00:00
|
|
|
if (left_.enabled) {
|
|
|
|
setLeft(!left_.set);
|
|
|
|
emit leftSet(left_.set);
|
|
|
|
}
|
2002-11-08 00:09:00 +00:00
|
|
|
} else {
|
2002-11-28 18:07:39 +00:00
|
|
|
if (bottom_.enabled) {
|
|
|
|
setBottom(!bottom_.set);
|
|
|
|
emit bottomSet(bottom_.set);
|
|
|
|
}
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-11-15 05:44:14 +00:00
|
|
|
if (e->y() < height() - e->x()) {
|
2002-11-28 18:07:39 +00:00
|
|
|
if (top_.enabled) {
|
|
|
|
setTop(!top_.set);
|
|
|
|
emit topSet(top_.set);
|
|
|
|
}
|
2002-11-08 00:09:00 +00:00
|
|
|
} else {
|
2002-11-28 18:07:39 +00:00
|
|
|
if (right_.enabled) {
|
|
|
|
setRight(!right_.set);
|
|
|
|
emit rightSet(right_.set);
|
|
|
|
}
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
update();
|
2002-11-27 18:47:09 +00:00
|
|
|
emit clicked();
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
|
2002-11-28 18:07:39 +00:00
|
|
|
void QSetBorder::drawLine(QColor const & col, int x, int y, int x2, int y2)
|
2002-11-08 00:09:00 +00:00
|
|
|
{
|
|
|
|
QPainter paint;
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.begin(&buffer);
|
2002-11-08 00:09:00 +00:00
|
|
|
QPen p = paint.pen();
|
|
|
|
p.setWidth(2);
|
2002-11-28 18:07:39 +00:00
|
|
|
p.setColor(col);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.setPen(p);
|
2002-11-27 20:23:53 +00:00
|
|
|
paint.drawLine(x, y, x2, y2);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.end();
|
|
|
|
}
|
2002-11-27 20:23:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
void QSetBorder::drawLeft(bool draw)
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
QColor col(draw ? Qt::black : Qt::white);
|
|
|
|
if (!left_.enabled)
|
|
|
|
col = QColor("grey");
|
|
|
|
drawLine(col, m + l, m + l + 2, m + l, h - m - l - 1);
|
2002-11-27 20:23:53 +00:00
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
|
|
|
|
void QSetBorder::drawRight(bool draw)
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
QColor col(draw ? Qt::black : Qt::white);
|
|
|
|
if (!right_.enabled)
|
|
|
|
col = QColor("grey");
|
|
|
|
drawLine(col, h - m - l + 1, m + l + 2, h - m - l + 1, h - m - l - 1);
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
void QSetBorder::drawTop(bool draw)
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
QColor col(draw ? Qt::black : Qt::white);
|
|
|
|
if (!top_.enabled)
|
|
|
|
col = QColor("grey");
|
|
|
|
drawLine(col, m + l + 2, m + l, w - m - l - 1, m + l);
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-11-27 20:23:53 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
void QSetBorder::drawBottom(bool draw)
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
QColor col(draw ? Qt::black : Qt::white);
|
|
|
|
if (!bottom_.enabled)
|
|
|
|
col = QColor("grey");
|
|
|
|
drawLine(col, m + l + 2, w - m - l + 1, w - m - l - 1, w - m - l + 1);
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-11-28 18:07:39 +00:00
|
|
|
|
|
|
|
void QSetBorder::setLeftEnabled(bool border)
|
|
|
|
{
|
|
|
|
left_.enabled = border;
|
|
|
|
drawLeft(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSetBorder::setRightEnabled(bool border)
|
|
|
|
{
|
|
|
|
right_.enabled = border;
|
|
|
|
drawRight(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSetBorder::setTopEnabled(bool border)
|
|
|
|
{
|
|
|
|
top_.enabled = border;
|
|
|
|
drawTop(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSetBorder::setBottomEnabled(bool border)
|
|
|
|
{
|
|
|
|
bottom_.enabled = border;
|
|
|
|
drawBottom(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
void QSetBorder::setLeft(bool border)
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
left_.set = border;
|
2002-11-27 18:47:09 +00:00
|
|
|
drawLeft(border);
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-11-27 20:23:53 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
void QSetBorder::setRight(bool border)
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
right_.set = border;
|
2002-11-27 18:47:09 +00:00
|
|
|
drawRight(border);
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
|
|
|
|
void QSetBorder::setTop(bool border)
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
top_.set = border;
|
2002-11-27 18:47:09 +00:00
|
|
|
drawTop(border);
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
|
|
|
|
void QSetBorder::setBottom(bool border)
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
bottom_.set = border;
|
2002-11-27 18:47:09 +00:00
|
|
|
drawBottom(border);
|
|
|
|
}
|
|
|
|
|
2002-11-27 20:23:53 +00:00
|
|
|
|
2002-11-27 18:47:09 +00:00
|
|
|
void QSetBorder::setAll(bool border)
|
|
|
|
{
|
|
|
|
setLeft(border);
|
|
|
|
setRight(border);
|
|
|
|
setTop(border);
|
|
|
|
setBottom(border);
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-11-27 20:23:53 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
bool QSetBorder::getLeft()
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
return left_.set;
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-11-27 20:23:53 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
bool QSetBorder::getRight()
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
return right_.set;
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-11-27 20:23:53 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
bool QSetBorder::getTop()
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
return top_.set;
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|
|
|
|
|
2002-11-27 20:23:53 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
bool QSetBorder::getBottom()
|
|
|
|
{
|
2002-11-28 18:07:39 +00:00
|
|
|
return bottom_.set;
|
2002-11-08 00:09:00 +00:00
|
|
|
}
|