Debian Codegraph @

src/framewidget.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2008, 2009 Andres Cabrera
3 [email protected]
4
5 This file is part of CsoundQt.
6
7 CsoundQt is free software; you can redistribute it
8 and/or modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 CsoundQt is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with Csound; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA
21 */
22
23 #include "framewidget.h"
24 #include "qutewidget.h"
25
26 #include <QColor>
27
28 FrameWidget::FrameWidget(QWidget* parent) : QFrame(parent)
29 {
30 this->setMinimumSize(2,2);
31 m_resizeBox = new QFrame(this);
32 m_resizeBox->setAutoFillBackground(true);
33 QPalette palette = QPalette((QColor(Qt::red)),(QColor(Qt::red)));
34 palette.setColor(QPalette::WindowText, QColor(Qt::red));
35 m_resizeBox->setPalette(palette);
36 m_resizeBox->show();
37 m_resizeBox->setMinimumSize(2,2);
38 m_selected = false;
39 m_changed = false;
40 this->setStyleSheet("QFrame, QLabel, QToolTip{color:black; border:2px solid green;}");
41 }
42
43 FrameWidget::~FrameWidget()
44 {
45 }
46
47 void FrameWidget::select()
48 {
49 m_selected = true;
50 this->setStyleSheet("QFrame, QLabel, QToolTip {color:black; border:3px solid rgb(30, 150, 240);}");
51
52 emit widgetSelected(m_widget);
53 }
54
55 void FrameWidget::setSelected(bool status) {
56 if(status) {
57 this->select();
58 } else
59 this->deselect();
60 }
61
62 void FrameWidget::deselect()
63 {
64 m_selected = false;
65 this->setStyleSheet("QFrame, QLabel, QToolTip {color:black; border:2px solid green;}");
66 emit widgetUnselected(m_widget);
67 }
68
69 bool FrameWidget::isSelected()
70 {
71 return m_selected;
72 }
73
74 void FrameWidget::contextMenuEvent(QContextMenuEvent *event)
75 {
76 emit(popUpMenu(event->globalPos()));
77 }
78
79 void FrameWidget::mousePressEvent ( QMouseEvent * event )
80 {
81 QFrame::mousePressEvent(event);
82 this->setFocus(Qt::MouseFocusReason);
83 if (event->button() & Qt::LeftButton) {
84 startx = event->x();
85 starty = event->y();
86 oldx = event->x();
87 oldy = event->y();
88 if (startx > (width()-7) && starty > (height()-7))
89 m_resize = true;
90 else
91 m_resize = false;
92 if (event->modifiers() & Qt::ShiftModifier) {
93 this->select();
94 } else if (event->modifiers() & Qt::ControlModifier) {
95 this->setSelected(!this->isSelected());
96 } else if(!isSelected()) {
97 emit deselectAllSignal();
98 this->select();
99 }
100 }
101 event->accept(); //to avoid propagation of the event to parent widgets
102 }
103
104 void FrameWidget::mouseReleaseEvent ( QMouseEvent * event )
105 {
106 QFrame::mouseReleaseEvent(event);
107 emit mouseReleased();
108 event->accept(); //to avoid propagation of the event to parent widgets
109 }
110
111 void FrameWidget::mouseMoveEvent (QMouseEvent* event)
112 {
113 if (m_resize) {
114 if(event->modifiers() & Qt::ShiftModifier) {
115 auto dx = event->x() - oldx;
116 auto dy = event->y() - oldy;
117 if(qAbs(dx) > qAbs(dy)) {
118 QPair<int,int> pair(dx, 0);
119 emit resized(pair);
120 } else {
121 QPair<int, int> pair(0, dy);
122 emit resized(pair);
123 }
124 } else {
125 QPair<int, int> pair(event->x()- oldx, event->y()- oldy);
126 emit resized(pair);
127 }
128 }
129 else {
130 QPair<int, int> pair(event->x()- startx, event->y()- starty);
131 emit moved(pair);
132 }
133 oldx = event->x();
134 oldy = event->y();
135 m_widget->markChanged();
136 m_changed = true;
137 }
138
139 void FrameWidget::mouseDoubleClickEvent (QMouseEvent * event)
140 {
141 event->accept();
142 emit editWidget();
143 }
144
145 void FrameWidget::resizeEvent (QResizeEvent* event)
146 {
147 QWidget::resizeEvent(event);
148 m_resizeBox->move(width()-7, height()-7);
149 m_resizeBox->resize(7,7);
150 }