1
/*******************************************************************
3
Part of the Fritzing project - http://fritzing.org
4
Copyright (c) 2007-2012 Fachhochschule Potsdam - http://fh-potsdam.de
6
Fritzing is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
11
Fritzing is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************
22
$Author: cohen@irascible.com $:
23
$Date: 2012-09-06 08:39:51 +0200 (Thu, 06 Sep 2012) $
25
********************************************************************/
30
#include "viewswitcherdockwidget.h"
31
#include "../debugdialog.h"
32
#include "viewswitcher.h"
39
const double inactiveOpacity = 0.6;
40
const double activeOpacity = 1.0;
42
ViewSwitcherDockWidget::ViewSwitcherDockWidget(const QString & title, QWidget * parent)
43
: FDockWidget(title, parent)
46
m_viewSwitcher = NULL;
49
bool floatFlag = true;
50
QPoint initial(10,50);
60
OSVERSIONINFO OSversion;
61
OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
62
::GetVersionEx(&OSversion);
63
//DebugDialog::debug(QString("windows os version %1 %2").arg(OSversion.dwMajorVersion).arg(OSversion.dwMinorVersion));
64
if (OSversion.dwMajorVersion > 5) {
65
// vista and win 7 major version is 6
73
setFloating(floatFlag);
74
m_offsetFromParent.setX(initial.x());
75
m_offsetFromParent.setY(initial.y());
77
// connect last so they doesn't trigger during construction
78
connect(this, SIGNAL(topLevelChanged(bool)), this, SLOT(topLevelChangedSlot(bool)));
79
connect(toggleViewAction(), SIGNAL(triggered()), this, SLOT(savePreference()), Qt::DirectConnection);
82
ViewSwitcherDockWidget::~ViewSwitcherDockWidget() {
88
void ViewSwitcherDockWidget::calcWithin()
90
QRect rw = parentWidget()->frameGeometry();
91
QRect rt = this->frameGeometry();
92
m_within = rw.contains(rt);
93
DebugDialog::debug(QString("tabwindow docked %1").arg(m_within));
95
m_offsetFromParent = rt.topLeft() - rw.topLeft();
99
void ViewSwitcherDockWidget::windowMoved(QWidget * widget) {
100
if (!this->isFloating()) return;
104
QRect rw = parentWidget()->frameGeometry();
105
this->move(rw.topLeft() + m_offsetFromParent);
112
bool ViewSwitcherDockWidget::event(QEvent *event)
114
bool result = FDockWidget::event(event);
116
switch (event->type()) {
117
case QEvent::MouseButtonRelease:
128
void ViewSwitcherDockWidget::setViewSwitcher(ViewSwitcher * viewSwitcher)
130
m_viewSwitcher = viewSwitcher;
131
setTitleBarWidget(viewSwitcher);
132
topLevelChangedSlotAux(isFloating());
135
void ViewSwitcherDockWidget::resizeEvent(QResizeEvent * event)
137
FDockWidget::resizeEvent(event);
140
void ViewSwitcherDockWidget::topLevelChangedSlot(bool topLevel) {
141
topLevelChangedSlotAux(topLevel);
145
void ViewSwitcherDockWidget::topLevelChangedSlotAux(bool topLevel) {
146
if (m_viewSwitcher == NULL) return;
153
this->setStyleSheet("border: 0px; margin: 0px; padding: 0px; border-radius: 0px; spacing: 0px;");
154
QRect r = this->geometry();
155
const QBitmap * mask = m_viewSwitcher->getMask();
156
QSize vssz = mask->size();
158
this->setMinimumSize(vssz);
159
//DebugDialog::debug(QString("mask size %1 %2").arg(vssz.width()).arg(vssz.height()));
160
r.setRect(r.left() + ((sz.width() - vssz.width()) / 2.0),
161
r.top() + ((sz.height() - vssz.height()) / 2.0),
164
this->setGeometry(r);
165
this->setMask(*mask);
168
void ViewSwitcherDockWidget::setVisible(bool visible) {
169
FDockWidget::setVisible(visible);
173
void ViewSwitcherDockWidget::prestorePreference() {
174
disconnect(this, SIGNAL(topLevelChanged(bool)), this, SLOT(topLevelChangedSlot(bool)));
177
void ViewSwitcherDockWidget::restorePreference() {
179
QVariant value = settings.value("viewswitcher/state");
180
if (!value.isNull()) {
181
// override visibility setting because if you close an inactive mainwindow
182
// the viewswitcher will be hidden, but that's not really the true state:
183
// the viewswitcher would be visible if the window were active
184
int v = value.toInt();
185
//DebugDialog::debug(QString("loading viewswitcher pref %1").arg(v));
186
bool vis = (v & 2) != 0;
188
// floating, so use m_state
191
// until the dock activation bug is fixed
200
connect(this, SIGNAL(topLevelChanged(bool)), this, SLOT(topLevelChangedSlot(bool)));
203
void ViewSwitcherDockWidget::savePreference() {
205
int v = isVisible() ? 2 : 0;
206
v += isFloating() ? 1 : 0;
207
//DebugDialog::debug(QString("saving viewswitcher pref (1):%1").arg(v));
208
settings.setValue("viewswitcher/state", v);