~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/designer/qdesigner_toolwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qdesigner.h"
 
30
#include "qdesigner_toolwindow.h"
 
31
#include "qdesigner_settings.h"
 
32
#include "qdesigner_workbench.h"
 
33
 
 
34
#include <QtCore/QEvent>
 
35
#include <QtCore/qdebug.h>
 
36
#include <QtGui/QAction>
 
37
#include <QtGui/QCloseEvent>
 
38
#include <QtGui/QWorkspace>
 
39
 
 
40
QDesignerToolWindow::QDesignerToolWindow(QDesignerWorkbench *workbench, QWidget *parent, Qt::WindowFlags flags)
 
41
    : QMainWindow(parent, flags),
 
42
      m_workbench(workbench),
 
43
      m_saveSettings(false)
 
44
{
 
45
    Q_ASSERT(workbench != 0);
 
46
 
 
47
    m_action = new QAction(this);
 
48
    m_action->setShortcutContext(Qt::ApplicationShortcut);
 
49
    m_action->setText(windowTitle());
 
50
    m_action->setCheckable(true);
 
51
    connect(m_action, SIGNAL(triggered(bool)), this, SLOT(showMe(bool)));
 
52
}
 
53
 
 
54
QDesignerToolWindow::~QDesignerToolWindow()
 
55
{
 
56
    if (workbench())
 
57
        workbench()->removeToolWindow(this);
 
58
}
 
59
 
 
60
void QDesignerToolWindow::showMe(bool v)
 
61
{
 
62
    QWidget *target = parentWidget() == 0 ? this : parentWidget();
 
63
 
 
64
    if (v)
 
65
        target->setWindowState(target->windowState() & ~Qt::WindowMinimized);
 
66
 
 
67
    target->setVisible(v);
 
68
}
 
69
 
 
70
void QDesignerToolWindow::showEvent(QShowEvent *e)
 
71
{
 
72
    Q_UNUSED(e);
 
73
 
 
74
    bool blocked = m_action->blockSignals(true);
 
75
    m_action->setChecked(true);
 
76
    m_action->blockSignals(blocked);
 
77
}
 
78
 
 
79
void QDesignerToolWindow::hideEvent(QHideEvent *e)
 
80
{
 
81
    Q_UNUSED(e);
 
82
 
 
83
    bool blocked = m_action->blockSignals(true);
 
84
    m_action->setChecked(false);
 
85
    m_action->blockSignals(blocked);
 
86
}
 
87
 
 
88
QAction *QDesignerToolWindow::action() const
 
89
{
 
90
    return m_action;
 
91
}
 
92
 
 
93
void QDesignerToolWindow::changeEvent(QEvent *e)
 
94
{
 
95
    switch (e->type()) {
 
96
        case QEvent::WindowTitleChange:
 
97
            m_action->setText(windowTitle());
 
98
            break;
 
99
        case QEvent::WindowIconChange:
 
100
            m_action->setIcon(windowIcon());
 
101
            break;
 
102
        default:
 
103
            break;
 
104
    }
 
105
    QMainWindow::changeEvent(e);
 
106
}
 
107
 
 
108
QDesignerWorkbench *QDesignerToolWindow::workbench() const
 
109
{
 
110
    return m_workbench;
 
111
}
 
112
 
 
113
QRect QDesignerToolWindow::geometryHint() const
 
114
{
 
115
    return QRect();
 
116
}
 
117
 
 
118
void QDesignerToolWindow::closeEvent(QCloseEvent *ev)
 
119
{
 
120
    if (m_saveSettings) {
 
121
        ev->setAccepted(workbench()->handleClose());
 
122
        if (ev->isAccepted() && qDesigner->mainWindow() == this) {
 
123
            if (qFindChild<QWorkspace *>(this)) {
 
124
                QDesignerSettings settings;
 
125
                settings.saveGeometryFor(this);
 
126
                settings.setValue(objectName() + QLatin1String("/visible"), false);
 
127
            }
 
128
            QMetaObject::invokeMethod(qDesigner, "quit", Qt::QueuedConnection);  // We're going down!
 
129
        }
 
130
    } else {
 
131
        QMainWindow::closeEvent(ev);
 
132
    }
 
133
}
 
134
 
 
135
bool QDesignerToolWindow::saveSettingsOnClose() const
 
136
{
 
137
    return m_saveSettings;
 
138
}
 
139
 
 
140
void QDesignerToolWindow::setSaveSettingsOnClose(bool save)
 
141
{
 
142
    m_saveSettings = save;
 
143
}
 
144
 
 
145
Qt::DockWidgetArea QDesignerToolWindow::dockWidgetAreaHint() const
 
146
{
 
147
    return Qt::RightDockWidgetArea;
 
148
}
 
149