2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiSetBorder.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiSetBorder.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPaintEvent>
|
|
|
|
|
|
|
|
|
2012-11-10 12:34:45 +00:00
|
|
|
GuiSetBorder::GuiSetBorder(QWidget * parent, Qt::WindowFlags fl)
|
2006-08-17 08:59:00 +00:00
|
|
|
: QWidget(parent, fl), buffer(75, 75)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
/* length of corner line */
|
|
|
|
l = buffer.width() / 10;
|
|
|
|
/* margin */
|
|
|
|
m = buffer.height() / 10;
|
|
|
|
|
|
|
|
w = buffer.width();
|
|
|
|
h = buffer.height();
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
|
|
|
setMinimumSize(w,h);
|
|
|
|
setMaximumSize(w,h);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::paintEvent(QPaintEvent * e)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QWidget::paintEvent(e);
|
2006-08-15 14:55:34 +00:00
|
|
|
QPainter painter(this);
|
|
|
|
painter.drawPixmap(0, 0, buffer);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::init()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
buffer.fill();
|
|
|
|
QPainter paint(&buffer);
|
|
|
|
|
|
|
|
paint.setPen(Qt::black);
|
|
|
|
|
|
|
|
// FIXME: wow, readable !! :)
|
|
|
|
|
|
|
|
paint.drawLine(m + l , m, m + l, m + l);
|
|
|
|
paint.drawLine(w - (m + l), m, w - (m + l), m + l);
|
|
|
|
|
|
|
|
paint.drawLine(m, m + l , m + l, m + l);
|
|
|
|
paint.drawLine(m, h - (m + l), m + l, h - (m + l));
|
|
|
|
|
|
|
|
paint.drawLine(m + l ,h - m, m + l ,h - (m + l));
|
|
|
|
paint.drawLine(w - (m + l), h - m, w - (m + l), h - (m + l));
|
|
|
|
|
|
|
|
paint.drawLine(h - m, m+l, h - (m + l), m + l);
|
|
|
|
paint.drawLine(h - m, h - (m + l), h - (m + l),h - (m + l));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::mousePressEvent(QMouseEvent * e)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
if (e->y() > e->x()) {
|
|
|
|
if (e->y() < height() - e->x()) {
|
|
|
|
if (left_.enabled) {
|
|
|
|
setLeft(!left_.set);
|
2007-05-28 22:27:45 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
leftSet(left_.set);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bottom_.enabled) {
|
|
|
|
setBottom(!bottom_.set);
|
2007-05-28 22:27:45 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
bottomSet(bottom_.set);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (e->y() < height() - e->x()) {
|
|
|
|
if (top_.enabled) {
|
|
|
|
setTop(!top_.set);
|
2007-05-28 22:27:45 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
topSet(top_.set);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (right_.enabled) {
|
|
|
|
setRight(!right_.set);
|
2007-05-28 22:27:45 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
rightSet(right_.set);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
update();
|
2007-05-28 22:27:45 +00:00
|
|
|
// emit signal
|
2006-06-30 14:11:50 +00:00
|
|
|
clicked();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::drawLine(QColor const & col, int x, int y, int x2, int y2)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QPainter paint(&buffer);
|
|
|
|
QPen p = paint.pen();
|
|
|
|
p.setWidth(2);
|
|
|
|
p.setColor(col);
|
|
|
|
paint.setPen(p);
|
|
|
|
paint.drawLine(x, y, x2, y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::drawLeft(bool draw)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QColor col(draw ? Qt::black : Qt::white);
|
|
|
|
if (!left_.enabled)
|
2010-01-31 13:15:26 +00:00
|
|
|
col = QColor(Qt::lightGray);
|
2006-03-05 17:24:44 +00:00
|
|
|
drawLine(col, m + l, m + l + 2, m + l, h - m - l - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::drawRight(bool draw)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QColor col(draw ? Qt::black : Qt::white);
|
|
|
|
if (!right_.enabled)
|
2010-01-31 13:15:26 +00:00
|
|
|
col = QColor(Qt::lightGray);
|
2006-03-05 17:24:44 +00:00
|
|
|
drawLine(col, h - m - l + 1, m + l + 2, h - m - l + 1, h - m - l - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::drawTop(bool draw)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QColor col(draw ? Qt::black : Qt::white);
|
|
|
|
if (!top_.enabled)
|
2010-01-31 13:15:26 +00:00
|
|
|
col = QColor(Qt::lightGray);
|
2006-03-05 17:24:44 +00:00
|
|
|
drawLine(col, m + l + 2, m + l, w - m - l - 1, m + l);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::drawBottom(bool draw)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QColor col(draw ? Qt::black : Qt::white);
|
|
|
|
if (!bottom_.enabled)
|
2010-01-31 13:15:26 +00:00
|
|
|
col = QColor(Qt::lightGray);
|
2006-03-05 17:24:44 +00:00
|
|
|
drawLine(col, m + l + 2, w - m - l + 1, w - m - l - 1, w - m - l + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::setLeftEnabled(bool border)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
left_.enabled = border;
|
|
|
|
drawLeft(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::setRightEnabled(bool border)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
right_.enabled = border;
|
|
|
|
drawRight(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::setTopEnabled(bool border)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
top_.enabled = border;
|
|
|
|
drawTop(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::setBottomEnabled(bool border)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
bottom_.enabled = border;
|
|
|
|
drawBottom(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::setLeft(bool border)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
left_.set = border;
|
|
|
|
drawLeft(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::setRight(bool border)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
right_.set = border;
|
|
|
|
drawRight(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::setTop(bool border)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
top_.set = border;
|
|
|
|
drawTop(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::setBottom(bool border)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
bottom_.set = border;
|
|
|
|
drawBottom(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSetBorder::setAll(bool border)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setLeft(border);
|
|
|
|
setRight(border);
|
|
|
|
setTop(border);
|
|
|
|
setBottom(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
bool GuiSetBorder::getLeft()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
return left_.set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
bool GuiSetBorder::getRight()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
return right_.set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
bool GuiSetBorder::getTop()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
return top_.set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
bool GuiSetBorder::getBottom()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
return bottom_.set;
|
|
|
|
}
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiSetBorder.cpp"
|