Qt QGraphicsProxyWidget与QGraphicsScene的交互

时间:2018-10-02 16:55:10

标签: c++ qt qgraphicsview qgraphicsscene qgraphicsitem

我试图用左侧的QSplitter和右侧的QTreeView制作一个QGraphicsView。这非常简单,我可以进行此工作。

现在,我的目标是将小部件嵌入QGraphicsView的场景中,使用QGraphicsProxyWidget为我分配给QGraphicsScene的{​​{1}}创建项目。这也是超级容易和工作。关于我希望这些小部件的外观和感觉有一个小警告。经过一些研究,根据我自己阅读和测试的内容,这似乎是不可能的。我将从当前需要的内容中发布相关代码,以进一步说明情况。

QGraphicsView

因此,鉴于此代码,我试图给MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); QPointer<QSplitter> splitter = new QSplitter; QPointer<QTreeView> tree = new QTreeView; splitter->addWidget(tree); QPointer<QVBoxLayout> layout = new QVBoxLayout; layout->addWidget(splitter); QPointer<QWidget> blueWidget = new QWidget; QPointer<QWidget> redWidget = new QWidget; blueWidget->setGeometry(250, 500, 250, 250); redWidget->setGeometry(500, 500, 250, 250); //This has no effect... blueWidget->setWindowFlags(Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint); redWidget->setWindowFlags( Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint); blueWidget->setWindowTitle("Blue Widget"); redWidget->setWindowTitle("Red Widget"); blueWidget->setStyleSheet(QString("background-color: rgb(0,0,255)")); redWidget->setStyleSheet(QString("background-color: rgb(255,0,0)")); QPointer<QGraphicsProxyWidget> proxy1 = new QGraphicsProxyWidget(nullptr, redWidget->windowFlags()); proxy1->setWidget(redWidget); proxy1->setWindowFlags(redWidget->windowFlags()); QPointer<QGraphicsProxyWidget> proxy2 = new QGraphicsProxyWidget; proxy2->setWidget(blueWidget); proxy2->setWindowFlags(blueWidget->windowFlags()); QPointer<QGraphicsScene> scene = new QGraphicsScene; scene->addItem(proxy1); scene->addItem(proxy2); scene->setSceneRect(0,0,1920,1080); QPointer<QGraphicsView> view = new QGraphicsView; view->setStyleSheet(QString("background-color: rgb(245,245,220)")); view->setScene(scene); view->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff ); view->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff ); splitter->addWidget(view); splitter->setStretchFactor( 0, 1 ); splitter->setStretchFactor( 1, 3 ); this->centralWidget()->setLayout(layout); } 中的QGraphicsItems一些QGraphicsScene。但是,似乎我没有栏(如果没有设置标志),或者只有栏和一个简单的关闭按钮,其样式与程序的其余部分不同(我认为取决于OS样式)。生成的标题栏没有弹出右键单击上下文菜单,就像常规Qt::WindowFlags所期望的那样。我只是想知道是否有可能克服操作系统似乎施加的这种限制。无论如何,QWidget都无法达到我一直期望的效果。我希望Qt::WindowFlags就是我所需要的,但是它不起作用,也没有明确添加Qt::Widget

我当时在想,也许我可以创建一个自定义Qt::WindowMinMaxButtonsHint / TitleBarWidget并接受TitleBarItem中的父项QGraphicsItemQWidget并应用使其与其父级的宽度匹配某个偏移量。然后,我可以实现此QGraphicsScene的单击和拖动事件以移动其父级。这样做可以让我添加自己的自定义标题位置,字体,甚至着色。另外,我可以创建自己的自定义样式的按钮并连接其单击的信号,以执行常规TitleBarWidget将执行的相应正确操作。

如果这看起来很复杂,那么这样做的目的是保持QWidget永远不会离开QGraphicsItems的{​​{1}}边界矩形区域的属性。我也有解决最小化和最大化问题的想法,因为如果将其最小化,将没有本机OS任务栏应用程序可供选择。

现在,如果这不起作用,则必须使用顶级QGraphicsScene's创建自己的场景管理器,并将每个QSplitter's QGraphicsView调整大小事件与发出的QWidgets拖动事件连接起来。 ..我真的不想做...

请,如果我在第一次尝试的实现中错过了一些基本知识,可以使它以最小的麻烦工作,那么如果有人可以向我指出正确的方向,将不胜感激。如果我用QWidget'sQSplitter's的第二个想法可能是我最好的选择,那就是最小化子类化和重组,那么我就顺其自然。我担心这也行不通,但我乐观地认为,如果它没有遇到与第一个实现相同的问题,我将使其正常工作。

1 个答案:

答案 0 :(得分:0)

经过几天的反复试验,我在前面引用的链接中完成了以前用户代码的修改版本。可以将此类Titlebar附加到任何较大的QWidget上,以作为整个窗口的面积。本质上,您需要使用QWidget创建一个QVBoxLayout。然后,创建另一个QWidget来保存窗口的实际内容,并将整个外部父项QWidget设置为该Titlebar's父项。这将使您可以自由设置Titlebar的样式并添加所需的任何按钮,图标,样式,而与操作系统无关。

#ifndef TITLEBAR_H
#define TITLEBAR_H

#include "ViewerItem.h"
#include <QWidget>
#include <QHBoxLayout>
#include <QPushButton>
#include <QPointer>
#include <QStyle>
#include <QLabel>
#include <QPainter>
#include <QPen>
#include <QMouseEvent>
#include <QEvent>
#include <QApplication>
#include <QRubberBand>
#include <QEvent>
#include <QPoint>
#include <QResizeEvent>
#include <QObject>
#include <QDebug>
#include <QGraphicsProxyWidget>
#include <QGraphicsView>

class ViewerItem;

class TitleBar : public QWidget{
    Q_OBJECT
public:
    TitleBar(QString title = "default", QWidget *parent = nullptr);
    void setWindowTitle(const QString& title);

    enum Edge{
        None = 0x0,
        Left = 0x1,
        Top = 0x2,
        Right = 0x4,
        Bottom = 0x8,
        TopLeft = 0x10,
        TopRight = 0x20,
        BottomLeft = 0x40,
        BottomRight = 0x80,
    };
    Q_ENUM(Edge);
    Q_DECLARE_FLAGS(Edges, Edge);

    void setBorderWidth(int);
    int borderWidth() const;

    ViewerItem *_parent = nullptr;
    QRubberBand *_rubberband = nullptr;
    bool _cursorchanged;
    bool _leftButtonPressed;
    Edges* _mousePress;
    Edges* _mouseMove;
    int _borderWidth;
    bool _dragStart = false;
    Qt::CursorShape _prevCursorShape = Qt::ArrowCursor;

protected slots:
    void paintEvent(QPaintEvent* event);
protected:
    bool eventFilter(QObject *o, QEvent *e) override;
    void mouseHover(QHoverEvent*);
    void mouseLeave(QHoverEvent *);
    void mousePress(QMouseEvent*);
    void mouseRelease(QMouseEvent*);
    void mouseMove(QMouseEvent*);
    void updateCursorShape(const QPoint &);
    void calculateCursorPosition(const QPoint &, const QRect &, Edges *);

private:
    QPointer<QStyle> style;

    QIcon closeIcon;
    QIcon maxIcon;
    QIcon minIcon;

    QPointer<QLabel> titleLabel;
    QPointer<QPushButton> minimizeButton;
    QPointer<QPushButton> maximizeButton;
    QPointer<QPushButton> closeButton;

    QPointer<QVBoxLayout> mainVLayout;
    QPointer<QHBoxLayout> mainHLayout;
    QPointer<QHBoxLayout> leftHLayout;
    QPointer<QHBoxLayout> rightHLayout;

    QPoint currentPos;

    QPointer<QGraphicsView> view;

};

Q_DECLARE_OPERATORS_FOR_FLAGS(TitleBar::Edges);

#endif // TITLEBAR_H

#include "Titlebar.h"

TitleBar::TitleBar(QString title, QWidget *parent) :
    QWidget(parent),
    _parent(qobject_cast<ViewerItem*>(parent)),
    _cursorchanged(false),
    _leftButtonPressed(false),
    _borderWidth(5){

        titleLabel = new QLabel;
        minimizeButton = new QPushButton;
        maximizeButton = new QPushButton;
        closeButton = new QPushButton;

        mainVLayout = new QVBoxLayout;
        mainHLayout = new QHBoxLayout;
        leftHLayout = new QHBoxLayout;
        rightHLayout = new QHBoxLayout;

        leftHLayout->addWidget(titleLabel);

        rightHLayout->addWidget(minimizeButton);
        rightHLayout->addWidget(maximizeButton);
        rightHLayout->addWidget(closeButton);

        mainHLayout->addLayout(leftHLayout);
        mainHLayout->addLayout(rightHLayout);

        mainVLayout->setAlignment(Qt::AlignTop);
        leftHLayout->setAlignment(Qt::AlignLeft);
        rightHLayout->setAlignment(Qt::AlignRight);
        mainVLayout->setContentsMargins(5,2.5,5,0);


        mainVLayout->addLayout(mainHLayout);
        setLayout(mainVLayout);

        setWindowTitle(title);

        style = qApp->style();
        closeIcon = style->standardIcon(QStyle::SP_TitleBarCloseButton);
        maxIcon = style->standardIcon(QStyle::SP_TitleBarMaxButton);
        minIcon = style->standardIcon(QStyle::SP_TitleBarMinButton);

        minimizeButton->setIcon(minIcon);
        maximizeButton->setIcon(maxIcon);
        closeButton->setIcon(closeIcon);

        minimizeButton->setMinimumWidth(30);
        maximizeButton->setMinimumWidth(30);
        closeButton->setMinimumWidth(30);

        titleLabel->setFixedHeight(20);

        minimizeButton->setFixedHeight(20);
        maximizeButton->setFixedHeight(20);
        closeButton->setFixedHeight(20);

        this->setFixedHeight(25);
        this->setMinimumWidth(90);

        //_parent->setMouseTracking(true);
        _parent->setWindowFlags(Qt::FramelessWindowHint);
        _parent->setAttribute(Qt::WA_Hover);
        _parent->installEventFilter(this);

        _rubberband = new QRubberBand(QRubberBand::Rectangle);

        _mousePress = new Edges(Edge::None);
        _mouseMove = new Edges(Edge::None);
}

void TitleBar::paintEvent(QPaintEvent *event){
    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing);
    QPainterPath path;
    path.addRect(QRectF(0, 0, width(), height()));
    QPen pen(Qt::black, 1);
    p.setPen(pen);
    p.fillPath(path, Qt::white);
    p.drawPath(path);

    QWidget::paintEvent(event);
}



void TitleBar::setWindowTitle(const QString& title){
    this->titleLabel->setText(title);
    QWidget::setWindowTitle(title);
}

bool TitleBar::eventFilter(QObject *o, QEvent*e) {
    if (e->type() == QEvent::MouseMove ||
        e->type() == QEvent::HoverMove ||
        e->type() == QEvent::Leave ||
        e->type() == QEvent::MouseButtonPress ||
        e->type() == QEvent::MouseButtonRelease) {


        switch (e->type()) {
            case QEvent::MouseMove:
                mouseMove(static_cast<QMouseEvent*>(e));
                return true;
                break;
            case QEvent::HoverMove:
                mouseHover(static_cast<QHoverEvent*>(e));
                return true;
                break;
            case QEvent::Leave: //We're actually leaving the widget after we go out of the geometry + borderWidth
                mouseLeave(static_cast<QHoverEvent*>(e));
                return true;
                break;
            case QEvent::MouseButtonPress:
                mousePress(static_cast<QMouseEvent*>(e));
                return true;
                break;
            case QEvent::MouseButtonRelease:
                mouseRelease(static_cast<QMouseEvent*>(e));
                return true;
                break;
            default:
                //e->accept();
                return true;
                break;
        }
    } else {
        return _parent->eventFilter(o, e);
    }

}

void TitleBar::mouseHover(QHoverEvent *e) {
    //if this parent object is in a container we need to mapToParent, not mapToGlobal like the original implementer's code
    updateCursorShape(_parent->mapToParent(e->pos()));

    //We need to make the bar transparent because it messes with the leave event of the widget "behind" it for the top, top left, and top right cursors
    //Only re-enable it when we want to for example, double click maximize or click the buttons
    //This will be determined if we're within the the bar's bounding rect minus the border value, in other words the cursor should be defaulted
    //This will prevent accidental drag events also
    if(this->geometry().marginsRemoved(QMargins(borderWidth(),borderWidth(),borderWidth(), 0)).contains(e->pos())){
        setAttribute(Qt::WA_TransparentForMouseEvents, false);
    }else{
        setAttribute(Qt::WA_TransparentForMouseEvents, true);
    }
    e->accept();
}

void TitleBar::mouseLeave(QHoverEvent *e) {
    if (!_leftButtonPressed) {
        *_mousePress = None;
        *_mouseMove = None;
        QApplication::restoreOverrideCursor();
        _cursorchanged = false;
        _prevCursorShape = Qt::ArrowCursor;
    }
    QWidget::leaveEvent(e);
}

void TitleBar::mousePress(QMouseEvent *e) {
    if(e->button() & Qt::LeftButton){
        _leftButtonPressed = true;
        currentPos = e->pos();
        calculateCursorPosition(e->pos(), _parent->geometry().marginsRemoved(QMargins(_borderWidth, _borderWidth, _borderWidth, _borderWidth)), _mousePress);
        if (!_mouseMove->testFlag(Edge::None)) {
            _rubberband->setGeometry(_parent->geometry());
        }

        //This area is ONLY on the title bar itself and determines repositioning of the parent
        //We're actually selecting the parent, not the bar, but it looks and feels like we are using the bar
        if(this->geometry().marginsRemoved(QMargins(borderWidth(),borderWidth() + 1,borderWidth(),0)).contains(e->pos())){
            _dragStart = true;
            _cursorchanged = false;
        }
    }
    e->accept();
}

void TitleBar::mouseRelease(QMouseEvent *e) {
    if (e->button() & Qt::LeftButton) {
        _leftButtonPressed = false;
        _dragStart = false;
    }
    e->accept();
}

void TitleBar::mouseMove(QMouseEvent *e) {
    if (_leftButtonPressed) {
        //For dragging the parent by its titlebar
        if (_dragStart) {
            QPoint diff = e->pos() - currentPos;
            _parent->move(_parent->pos() + diff);
            return;
        }

        //For determining how to resize if we have an edge
        if (!_mouseMove->testFlag(Edge::None)) {
            int left = _rubberband->geometry().left();
            int top = _rubberband->geometry().top();
            int right = _rubberband->geometry().right();
            int bottom = _rubberband->geometry().bottom();

            switch (*_mouseMove) {

                case Edge::Top:
                    top = e->pos().y();                 
                    if(_parent->height() - top <= _parent->minimumHeight()) top = 0;
                    _parent->resize(QSize(_parent->width(), _parent->height() - top));
                    _rubberband->resize(QSize(_parent->width(), _parent->height() - top));                    
                    _parent->move(QPoint(_parent->x(), _parent->y() + top));
                    _rubberband->move(QPoint(_parent->x(), _parent->y() + top));
                    break;

                case Edge::Bottom: //Good
                    bottom = e->pos().y();
                    if(bottom > _parent->height()){ //growing down
                        _parent->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                    }else{ //shrinking up
                        _parent->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                    }
                    break;

                case Edge::Left: //Good
                    left = e->pos().x();
                    if(left <= 0){ //Dragging left
                        if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                        _parent->resize(QSize(_parent->width() - left, _parent->height()));
                        _rubberband->resize(QSize(_parent->width() - left, _parent->height()));
                        _parent->move(QPoint(_parent->x() + left, _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + left, _parent->y()));
                    }else{ //dragging right
                        if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                        _parent->resize(QSize(_parent->width() - left, _parent->height()));
                        _rubberband->resize(QSize(_parent->width() - left, _parent->height()));
                        _parent->move(QPoint(_parent->x() + left, _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + left, _parent->y()));
                    }
                    break;

                case Edge::Right:
                    right = e->pos().x();
                    if(right >= 0){ //Dragging right
                        _parent->resize(QSize(right, _parent->height()));
                        _rubberband->resize(QSize(right, _parent->height()));
                        if(_parent->width() - right <= _parent->minimumWidth()) break;
                        _parent->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                    }
                    break;

                case Edge::TopLeft:
                    top = e->pos().y();
                    left = e->pos().x();
                    if(_parent->height() - top <= _parent->minimumHeight()) top = 0;
                    if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                    _parent->resize(QSize(_parent->width() - left, _parent->height() - top));
                    _rubberband->resize(QSize(_parent->width() - left, _parent->height() - top));
                    _parent->move(QPoint(_parent->x() + left, _parent->y() + top));
                    _rubberband->move(QPoint(_parent->x() + left, _parent->y() + top));
                    break;

                case Edge::TopRight:
                    right = e->pos().x();
                    top = e->pos().y();
                    if(_parent->height() - top <= _parent->minimumHeight()) top = 0;
                    _parent->resize(QSize(_parent->width(), _parent->height() - top));
                    _rubberband->resize(QSize(_parent->width(), _parent->height() - top));
                    _parent->move(QPoint(_parent->x(), _parent->y() + top));
                    _rubberband->move(QPoint(_parent->x(), _parent->y() + top));
                    if(right >= 0){ //Dragging right
                        _parent->resize(QSize(right, _parent->height()));
                        _rubberband->resize(QSize(right, _parent->height()));
                        if(_parent->width() - right <= _parent->minimumWidth()) break;
                        _parent->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                    }
                    break;
                case Edge::BottomLeft:
                    bottom = e->pos().y();
                    left = e->pos().x();
                    if(bottom > _parent->height()){ //growing down
                        _parent->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                    }else{ //shrinking up
                        _parent->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                    }
                    if(left <= 0){ //Dragging left
                        if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                        _parent->resize(QSize(_parent->width() - left, _parent->height()));
                        _rubberband->resize(QSize(_parent->width() - left, _parent->height()));
                        _parent->move(QPoint(_parent->x() + left, _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + left, _parent->y()));
                    }else{ //dragging right
                        if(_parent->width() - left <= _parent->minimumWidth()) left = 0;
                        _parent->resize(QSize(_parent->width() - left, _parent->height()));
                        _rubberband->resize(QSize(_parent->width() - left, _parent->height()));
                        _parent->move(QPoint(_parent->x() + left, _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + left, _parent->y()));
                    }
                    break;
                case Edge::BottomRight:
                    bottom = e->pos().y();
                    right = e->pos().x();
                    if(bottom > _parent->height()){ //growing down
                        _parent->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() + (bottom - _parent->height())));
                    }else{ //shrinking up
                        _parent->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                        _rubberband->resize(QSize(_parent->width(), _parent->height() - (_parent->height() - bottom)));
                    }
                    if(right >= 0){ //Dragging right
                        _parent->resize(QSize(right, _parent->height()));
                        _rubberband->resize(QSize(right, _parent->height()));
                        if(_parent->width() - right <= _parent->minimumWidth()) break;
                        _parent->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                        _rubberband->move(QPoint(_parent->x() + (_parent->width() - right), _parent->y()));
                    }
                    break;
                default:
                    break;
            }
        }
    }
    e->accept();
}

void TitleBar::updateCursorShape(const QPoint &pos) {
    if (_parent->isFullScreen() || _parent->isMaximized()) {
        if (_cursorchanged) {
            QApplication::restoreOverrideCursor();
        }
        return;
    }
    if (!_leftButtonPressed) {
        calculateCursorPosition(pos, _parent->geometry(), _mouseMove);
        _cursorchanged = true;
        if (_mouseMove->testFlag(Edge::Top) || _mouseMove->testFlag(Edge::Bottom)) {
            if(_prevCursorShape != Qt::SizeVerCursor){
                QApplication::setOverrideCursor(Qt::SizeVerCursor);
            }
            _prevCursorShape = Qt::SizeVerCursor;
        } else if (_mouseMove->testFlag(Edge::Left) || _mouseMove->testFlag(Edge::Right)) {
            if(_prevCursorShape != Qt::SizeHorCursor){
                QApplication::setOverrideCursor(Qt::SizeHorCursor);
            }
            _prevCursorShape = Qt::SizeHorCursor;
        } else if (_mouseMove->testFlag(Edge::TopLeft) || _mouseMove->testFlag(Edge::BottomRight)) {
            if(_prevCursorShape != Qt::SizeFDiagCursor){
                QApplication::setOverrideCursor(Qt::SizeFDiagCursor);
            }
            _prevCursorShape = Qt::SizeFDiagCursor;
        } else if (_mouseMove->testFlag(Edge::TopRight) || _mouseMove->testFlag(Edge::BottomLeft)) {
            if(_prevCursorShape != Qt::SizeBDiagCursor){
                QApplication::setOverrideCursor(Qt::SizeBDiagCursor);
            }
            _prevCursorShape = Qt::SizeBDiagCursor;
        } else if (_cursorchanged && _mouseMove->testFlag(Edge::None)) {
            QApplication::restoreOverrideCursor();
            _cursorchanged = false;
            _prevCursorShape = Qt::ArrowCursor;
        }
    }
}

void TitleBar::calculateCursorPosition(const QPoint &pos, const QRect &framerect, Edges* _edge) {

    bool onLeft = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + (_borderWidth * 2) &&
        pos.y() <= framerect.y() + framerect.height() - (_borderWidth * 4) && pos.y() >= framerect.y() + (_borderWidth * 4);

    bool onRight = pos.x() >= framerect.x() + framerect.width() - (_borderWidth * 2) && pos.x() <= framerect.x() + framerect.width() - (_borderWidth) &&
        pos.y() >= framerect.y() + (_borderWidth * 4) && pos.y() <= framerect.y() + framerect.height() - (_borderWidth * 4);

    bool onBottom = pos.x() >= framerect.x() + (_borderWidth * 4) && pos.x() <= framerect.x() + framerect.width() - (_borderWidth * 4) &&
        pos.y() >= framerect.y() + framerect.height() - (_borderWidth * 2) && pos.y() <= framerect.y() + framerect.height() - _borderWidth;

    bool onTop = pos.x() >= framerect.x() + (_borderWidth * 4) && pos.x() <= framerect.x() + framerect.width() - (_borderWidth  * 4) &&
        pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + (_borderWidth * 2);

    bool onBottomLeft = pos.x() <= framerect.x() + (_borderWidth * 3) && pos.x() >= framerect.x() + _borderWidth &&
        pos.y() <= framerect.y() + framerect.height() -_borderWidth && pos.y() >= framerect.y() + framerect.height() - (_borderWidth * 4);

    bool onBottomRight = pos.x() >= framerect.x() + framerect.width() - (_borderWidth * 4) && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
        pos.y() >= framerect.y() + framerect.height() - (_borderWidth * 4) && pos.y() <= framerect.y() + framerect.height() - _borderWidth;

    bool onTopRight = pos.x() >= framerect.x() + framerect.width() - (_borderWidth * 4) && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
        pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + (_borderWidth * 4);

    bool onTopLeft = pos.x() >= framerect.x() - _borderWidth && pos.x() <= framerect.x() + (_borderWidth * 4) &&
        pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + (_borderWidth * 4);

    if (onLeft) {
        *_edge = Left;
        //qDebug() << "Left";
    } else if (onRight) {
        *_edge = Right;
        //qDebug() << "Right";
    } else if (onBottom) {
        *_edge = Bottom;
        //qDebug() << "bottom";
    } else if (onTop) {
        *_edge = Top;
        //qDebug() << "top";
    } else if (onBottomLeft) {
        *_edge = BottomLeft;
        //qDebug() << "bottom left";
    } else if (onBottomRight) {
        *_edge = BottomRight;
        //qDebug() << "Bottom right";
    } else if (onTopRight) {
        *_edge = TopRight;
        //qDebug() << "Top right";
    } else if (onTopLeft) {
        *_edge = TopLeft;
        //qDebug() << "Top left";
    } else {
        *_edge = None;
        //qDebug() << "None";
    }

}

void TitleBar::setBorderWidth(int borderWidth) {
    _borderWidth = borderWidth;
}

int TitleBar::borderWidth() const {
    return _borderWidth;
}