2002-11-08 00:09:00 +00:00
|
|
|
/**
|
|
|
|
* \file QSetBorder.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qpixmap.h>
|
|
|
|
#include <qimage.h>
|
|
|
|
#include "qsetborder.h"
|
|
|
|
|
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
QSetBorder::QSetBorder(QWidget * parent, char const * name, WFlags fl)
|
|
|
|
: QWidget(parent, name, fl),
|
2002-11-08 00:09:00 +00:00
|
|
|
left_(false), right_(false), top_(false), bottom_(false), buffer(75,75)
|
|
|
|
{
|
|
|
|
/* 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-11-15 05:44:14 +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-11-08 00:09:00 +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
|
|
|
|
|
|
|
|
|
|
|
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-08 00:09:00 +00:00
|
|
|
drawLeft(!left_);
|
|
|
|
left_ = !left_;
|
|
|
|
emit leftSet(left_);
|
|
|
|
} else {
|
|
|
|
drawBottom(!bottom_);
|
|
|
|
bottom_ = !bottom_;
|
|
|
|
emit bottomSet(bottom_);
|
|
|
|
}
|
|
|
|
} else {
|
2002-11-15 05:44:14 +00:00
|
|
|
if (e->y() < height() - e->x()) {
|
2002-11-08 00:09:00 +00:00
|
|
|
drawTop(!top_);
|
|
|
|
top_ = !top_;
|
|
|
|
emit topSet(top_);
|
|
|
|
} else {
|
|
|
|
drawRight(!right_);
|
|
|
|
right_ = !right_;
|
|
|
|
emit rightSet(right_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2002-11-15 05:44:14 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
void QSetBorder::drawLeft(bool draw)
|
|
|
|
{
|
|
|
|
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-15 05:44:14 +00:00
|
|
|
p.setColor(draw ? Qt::black : Qt::white);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.setPen(p);
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.drawLine(m + l, m + l + 2, m + l, h - m - l - 1);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.end();
|
|
|
|
}
|
2002-11-15 05:44:14 +00:00
|
|
|
|
2002-11-08 00:09:00 +00:00
|
|
|
|
|
|
|
void QSetBorder::drawRight(bool draw)
|
|
|
|
{
|
|
|
|
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-15 05:44:14 +00:00
|
|
|
p.setColor(draw ? Qt::black : Qt::white);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.setPen(p);
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.drawLine(h - m - l + 1, m + l + 2, h - m - l + 1, h - m - l - 1);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSetBorder::drawTop(bool draw)
|
|
|
|
{
|
|
|
|
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-15 05:44:14 +00:00
|
|
|
p.setColor(draw ? Qt::black : Qt::white);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.setPen(p);
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.drawLine(m + l + 2, m + l, w - m - l - 1, m + l);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSetBorder::drawBottom(bool draw)
|
|
|
|
{
|
|
|
|
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-15 05:44:14 +00:00
|
|
|
p.setColor(draw ? Qt::black : Qt::white);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.setPen(p);
|
2002-11-15 05:44:14 +00:00
|
|
|
paint.drawLine(m + l + 2, w - m - l + 1, w - m - l - 1, w - m - l + 1);
|
2002-11-08 00:09:00 +00:00
|
|
|
paint.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSetBorder::setLeft(bool border)
|
|
|
|
{
|
|
|
|
left_ = border;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSetBorder::setRight(bool border)
|
|
|
|
{
|
|
|
|
right_ = border;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSetBorder::setTop(bool border)
|
|
|
|
{
|
|
|
|
top_ = border;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSetBorder::setBottom(bool border)
|
|
|
|
{
|
|
|
|
bottom_ = border;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QSetBorder::getLeft()
|
|
|
|
{
|
|
|
|
return left_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QSetBorder::getRight()
|
|
|
|
{
|
|
|
|
return right_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QSetBorder::getTop()
|
|
|
|
{
|
|
|
|
return top_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QSetBorder::getBottom()
|
|
|
|
{
|
|
|
|
return bottom_;
|
|
|
|
}
|