~ubuntu-branches/ubuntu/trusty/fritzing/trusty-proposed

« back to all changes in this revision

Viewing changes to src/dock/viewswitcherdockwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Enrique Hernández Bello
  • Date: 2012-11-11 21:38:56 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20121111213856-0825ywdrtdcshl91
Tags: 0.7.10b-1
* New upstream version. Closes: #661495, #692998
* Removed useless patches.
* Removed SetupAPI.lib from sourceless files.
* Skip dfsg tarball creation if there are no sourceless files.
* Added libqt4-sql-sqlite to dependencies. Thanks to Tom Hummel <tom@bluespice.org>.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************
 
2
 
 
3
Part of the Fritzing project - http://fritzing.org
 
4
Copyright (c) 2007-2012 Fachhochschule Potsdam - http://fh-potsdam.de
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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/>.
 
18
 
 
19
********************************************************************
 
20
 
 
21
$Revision: 6373 $:
 
22
$Author: cohen@irascible.com $:
 
23
$Date: 2012-09-06 08:39:51 +0200 (Thu, 06 Sep 2012) $
 
24
 
 
25
********************************************************************/
 
26
 
 
27
#include <QtGui>
 
28
#include <QPainter>
 
29
 
 
30
#include "viewswitcherdockwidget.h"
 
31
#include "../debugdialog.h"
 
32
#include "viewswitcher.h"
 
33
 
 
34
#ifdef Q_WS_WIN
 
35
#include "windows.h"
 
36
#endif
 
37
 
 
38
 
 
39
const double inactiveOpacity = 0.6;
 
40
const double activeOpacity = 1.0;
 
41
 
 
42
ViewSwitcherDockWidget::ViewSwitcherDockWidget(const QString & title, QWidget * parent)
 
43
    : FDockWidget(title, parent)
 
44
{
 
45
        m_bitmap = NULL;
 
46
        m_viewSwitcher = NULL;
 
47
        m_within = true;
 
48
 
 
49
        bool floatFlag = true;
 
50
        QPoint initial(10,50);
 
51
 
 
52
#ifdef Q_WS_MAC
 
53
        initial.setY(34);
 
54
#else
 
55
        #ifdef Q_WS_X11
 
56
                floatFlag = false;
 
57
                initial.setY(60);
 
58
        #else
 
59
                #ifdef Q_WS_WIN
 
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
 
66
                initial.setX(12);
 
67
                initial.setY(60);
 
68
                        }
 
69
                #endif
 
70
        #endif
 
71
#endif
 
72
 
 
73
        setFloating(floatFlag);
 
74
        m_offsetFromParent.setX(initial.x());
 
75
        m_offsetFromParent.setY(initial.y());
 
76
 
 
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);
 
80
}
 
81
 
 
82
ViewSwitcherDockWidget::~ViewSwitcherDockWidget() {
 
83
        if (m_bitmap) {
 
84
                delete m_bitmap;
 
85
        }
 
86
}
 
87
 
 
88
void ViewSwitcherDockWidget::calcWithin()
 
89
{
 
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));
 
94
        if (m_within) {
 
95
                m_offsetFromParent = rt.topLeft() - rw.topLeft();
 
96
        }
 
97
}
 
98
 
 
99
void ViewSwitcherDockWidget::windowMoved(QWidget * widget) {
 
100
        if (!this->isFloating()) return;
 
101
 
 
102
        Q_UNUSED(widget);
 
103
        if (m_within) {
 
104
                QRect rw = parentWidget()->frameGeometry();
 
105
                this->move(rw.topLeft() + m_offsetFromParent);
 
106
        }
 
107
        else {
 
108
                calcWithin();
 
109
        }
 
110
}
 
111
 
 
112
bool ViewSwitcherDockWidget::event(QEvent *event)
 
113
{
 
114
        bool result = FDockWidget::event(event);
 
115
        if (isFloating()) {
 
116
                switch (event->type()) {
 
117
                        case QEvent::MouseButtonRelease:
 
118
                                calcWithin();
 
119
                                break;
 
120
                        default:
 
121
                                break;
 
122
                }
 
123
 
 
124
        }
 
125
        return result;
 
126
}
 
127
 
 
128
void ViewSwitcherDockWidget::setViewSwitcher(ViewSwitcher * viewSwitcher)
 
129
{
 
130
        m_viewSwitcher = viewSwitcher;
 
131
        setTitleBarWidget(viewSwitcher);
 
132
        topLevelChangedSlotAux(isFloating());
 
133
}
 
134
 
 
135
void ViewSwitcherDockWidget::resizeEvent(QResizeEvent * event)
 
136
{
 
137
        FDockWidget::resizeEvent(event);
 
138
}
 
139
 
 
140
void ViewSwitcherDockWidget::topLevelChangedSlot(bool topLevel) {
 
141
        topLevelChangedSlotAux(topLevel);
 
142
        savePreference();
 
143
}
 
144
 
 
145
void ViewSwitcherDockWidget::topLevelChangedSlotAux(bool topLevel) {
 
146
        if (m_viewSwitcher == NULL) return;
 
147
 
 
148
        if (!topLevel) {
 
149
                this->clearMask();
 
150
                return;
 
151
        }
 
152
 
 
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();
 
157
        QSize sz = 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), 
 
162
                                vssz.width(), 
 
163
                                vssz.height());
 
164
        this->setGeometry(r);
 
165
        this->setMask(*mask);
 
166
}
 
167
 
 
168
void ViewSwitcherDockWidget::setVisible(bool visible) {
 
169
        FDockWidget::setVisible(visible);
 
170
}
 
171
 
 
172
 
 
173
void ViewSwitcherDockWidget::prestorePreference() {
 
174
        disconnect(this, SIGNAL(topLevelChanged(bool)), this, SLOT(topLevelChangedSlot(bool)));
 
175
}
 
176
 
 
177
void ViewSwitcherDockWidget::restorePreference() {
 
178
        QSettings settings;
 
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;
 
187
                if ((v & 1) == 1) {
 
188
                        // floating, so use m_state
 
189
                        setVisible(vis);
 
190
#ifndef Q_WS_X11
 
191
                        // until the dock activation bug is fixed
 
192
                        setFloating(true);
 
193
#endif
 
194
                }
 
195
                else {
 
196
                        setVisible(vis);
 
197
                        setFloating(false);
 
198
                }
 
199
        }
 
200
        connect(this, SIGNAL(topLevelChanged(bool)), this, SLOT(topLevelChangedSlot(bool)));
 
201
}
 
202
 
 
203
void ViewSwitcherDockWidget::savePreference() {
 
204
        QSettings settings;
 
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);
 
209
}
 
210