Debian Codegraph @

src/widgetpanel.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 "widgetpanel.h"
24 #include "widgetlayout.h"
25
26 #include "qutecsound.h"
27
28 WidgetPanel::WidgetPanel(QWidget *parent)
29 : QDockWidget(parent)
30 {
31 setWindowTitle("Widgets");
32 setMinimumSize(200, 140);
33 // connect(this,SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(dockLocationChanged(Qt::DockWidgetArea)));
34 //connect(this,SIGNAL(topLevelChanged(bool)), this, SLOT(dockStateChanged(bool)));
35
36 m_stack = new QStackedWidget(this);
37 m_stack->show();
38 setWidget(m_stack);
39
40 setMouseTracking(true);
41 }
42
43 WidgetPanel::~WidgetPanel()
44 {
45 }
46
47 void WidgetPanel::addWidgetLayout(WidgetLayout *w)
48 {
49 QScrollArea *scrollArea;
50 scrollArea = new QScrollArea(this);
51 scrollArea->setWidget(w);
52 m_stack->addWidget(scrollArea);
53 m_stack->setFocusProxy(w);
54 scrollArea->setFocusProxy(w);
55 // QHBoxLayout *l = new QHBoxLayout(this);
56 // l->addWidget(scrollArea);
57 // stack->setLayout(l);
58 connect(scrollArea->horizontalScrollBar(), SIGNAL(valueChanged(int)),
59 this, SLOT(scrollBarMoved(int)));
60 connect(scrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)),
61 this, SLOT(scrollBarMoved(int)));
62 w->setContained(true);
63 QRect outer = w->getOuterGeometry();
64
65 this->setGeometry(outer);
66 w->blockSignals(true);
67 w->adjustLayoutSize();
68 w->show();
69 scrollArea->show();
70 w->blockSignals(false);
71 }
72
73 WidgetLayout * WidgetPanel::takeWidgetLayout(QRect outerGeometry)
74 {
75 // qDebug() << "WidgetPanel::takeWidgetLayout()";
76 disconnect(this,SIGNAL(topLevelChanged(bool)));
77 QScrollArea *s = (QScrollArea*) m_stack->currentWidget();
78 if (!s) // scroll area is sometimes null during startup and shutdown
79 return nullptr;
80 // This transfers ownership of the widget to the caller
81 WidgetLayout *w = (WidgetLayout *) s->takeWidget();
82 if (w != nullptr) {
83 w->setOuterGeometry(outerGeometry);
84 w->setContained(false); // Must set before removing from container to get background
85 disconnect(w, SIGNAL(selection(QRect)), 0, 0);
86 }
87 m_stack->removeWidget(s);
88 delete s;
89 return w;
90 }
91
92 QRect WidgetPanel::getOuterGeometry()
93 {
94 QRect g;
95 QScrollArea *s = (QScrollArea*) m_stack->currentWidget();
96 if (s){
97 if (x() >= 0 && y() >= 0) {
98 g = this->geometry();
99 }
100 }
101 return g;
102 }
103
104 void WidgetPanel::closeEvent(QCloseEvent * /*event*/)
105 {
106 emit Close(false);
107 }
108
109 void WidgetPanel::contextMenuEvent(QContextMenuEvent *event)
110 {
111 QScrollArea *s = (QScrollArea*) m_stack->currentWidget();
112 Q_ASSERT(s != nullptr);
113 static_cast<WidgetLayout *>(s->widget())->createContextMenu(event);
114 }
115
116 void WidgetPanel::mousePressEvent(QMouseEvent * event)
117 {
118 QScrollArea *s = (QScrollArea*) m_stack->currentWidget();
119 if (!s) // scroll area is sometimes null during startup and shutdown
120 return;
121 static_cast<WidgetLayout *>(s->widget())->mousePressEventParent(event);
122 }
123
124 void WidgetPanel::mouseReleaseEvent(QMouseEvent * event)
125 {
126 QScrollArea *s = (QScrollArea*) m_stack->currentWidget();
127 if (!s) // scroll area is sometimes null during startup and shutdown
128 return;
129 static_cast<WidgetLayout *>(s->widget())->mouseReleaseEventParent(event);
130 }
131
132 void WidgetPanel::mouseMoveEvent(QMouseEvent * event)
133 {
134 QScrollArea *s = (QScrollArea*) m_stack->currentWidget();
135 if (!s) // scroll area is sometimes null during startup and shutdown
136 return;
137 WidgetLayout *w = static_cast<WidgetLayout *>(s->widget());
138 if (w != nullptr) {
139 w->mouseMoveEventParent(event);
140 }
141 }
142
143 void WidgetPanel::scrollBarMoved(int /*value*/)
144 {
145 QScrollArea *s = (QScrollArea*) m_stack->currentWidget();
146 if (!s) // scroll area is sometimes null during startup and shutdown
147 return;
148 int v = s->verticalScrollBar()->value();
149 int h = s->horizontalScrollBar()->value();
150 static_cast<WidgetLayout *>(s->widget())->setMouseOffset(h, v);
151 }