~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

« back to all changes in this revision

Viewing changes to scribus/sctoolbar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2009-02-09 09:25:18 UTC
  • mfrom: (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090209092518-iqsxmh3pjspgrdyd
Tags: 1.3.5.dfsg~svn20090208-2
debian/control: Use "type-handling -n arm,armel,armeb any" to generate the
list of architectures to build on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
25
25
 ***************************************************************************/
26
26
 
 
27
#include <QEvent>
 
28
#include <QMenu>
 
29
#include <QPixmap>
 
30
#include <QString>
 
31
#include <QToolButton>
 
32
 
27
33
#include "sctoolbar.h"
28
 
#include "sctoolbar.moc"
 
34
 
29
35
#include "prefscontext.h"
30
36
#include "prefsfile.h"
31
37
#include "prefsmanager.h"
32
 
#include <qevent.h>
33
 
#include <qdockarea.h>
34
 
#include <qdockwindow.h>
35
 
#include <qmainwindow.h>
36
 
#include <qstring.h>
37
 
#include <qtoolbutton.h>
38
 
#include <qpopupmenu.h>
39
 
 
40
 
extern QPixmap loadIcon(QString nam);
41
 
 
42
 
ScToolBar::ScToolBar(const QString& name, const QString &prefName, QMainWindow *parent, QDockWindow::Orientation o)
 
38
#include "util_icon.h"
 
39
 
 
40
ScToolBar::ScToolBar(const QString& name, const QString &prefName, QMainWindow *parent, Qt::Orientation o)
43
41
: QToolBar(name, parent),
44
42
  m_name(QString("ToolBar-%1").arg(prefName)),
45
43
  m_prefs(PrefsManager::instance()->prefsFile->getContext(m_name))
46
44
{
47
 
        hide();
48
 
        setCloseMode(QDockWindow::Undocked);
 
45
        setObjectName(name);
 
46
//      hide();
 
47
        parentMW=parent;
 
48
        
 
49
        setAllowedAreas(Qt::AllToolBarAreas);
 
50
        this->setIconSize(QSize(16,16));
 
51
        /*
 
52
        setCloseMode(Q3DockWindow::Undocked);
49
53
 
50
54
        if (m_prefs->contains("IsDocked")) // set docking
51
55
        {
68
72
        if (m_prefs->contains("FloatOrientation")) // set float orientation
69
73
        {
70
74
                floatOrientation = m_prefs->getInt("FloatOrientation", 1) == Hor ?
71
 
                                   QDockWindow::Horizontal : QDockWindow::Vertical;
 
75
                                   Qt::Horizontal : Qt::Vertical;
72
76
        }
73
77
        else
74
78
        {
75
79
                floatOrientation = o;
76
 
                m_prefs->set("FloatOrientation", o == QDockWindow::Horizontal ? Hor : Vert);
 
80
                m_prefs->set("FloatOrientation", o == Qt::Horizontal ? Hor : Vert);
77
81
        }
78
82
 
79
83
        if (!m_prefs->contains("PosIndex"))
85
89
        dockRight = m_prefs->getBool("DockRight", 1);
86
90
        dockBottom = m_prefs->getBool("DockBottom", 1);
87
91
        dockLeft = m_prefs->getBool("DockLeft", 1);
88
 
        mainWindow()->setDockEnabled(this, DockTop, dockTop);
89
 
        mainWindow()->setDockEnabled(this, DockRight, dockRight);
90
 
        mainWindow()->setDockEnabled(this, DockBottom, dockBottom);
91
 
        mainWindow()->setDockEnabled(this, DockLeft, dockLeft);
 
92
        mainWindow()->setDockEnabled(this, Qt::DockTop, dockTop);
 
93
        mainWindow()->setDockEnabled(this, Qt::DockRight, dockRight);
 
94
        mainWindow()->setDockEnabled(this, Qt::DockBottom, dockBottom);
 
95
        mainWindow()->setDockEnabled(this, Qt::DockLeft, dockLeft);
92
96
 
93
97
        if (place() == InDock)
94
98
                setOrientation(area()->orientation());
96
100
                setOrientation(floatOrientation);
97
101
 
98
102
        initPrefsButton();
 
103
        */
99
104
        languageChange();
100
105
 
101
 
        connect(this, SIGNAL(placeChanged(QDockWindow::Place)),
102
 
                this, SLOT(slotPlaceChanged(QDockWindow::Place)));
 
106
//      connect(this, SIGNAL(placeChanged(Q3DockWindow::Place)), this, SLOT(slotPlaceChanged(Q3DockWindow::Place)));
103
107
}
104
 
 
 
108
/*
105
109
void ScToolBar::initVisibility()
106
110
{
107
111
        if (m_prefs->getBool("IsVisible", true))
119
123
 
120
124
int ScToolBar::position()
121
125
{
122
 
        if (place() == QDockWindow::OutsideDock)
 
126
        if (place() == Q3DockWindow::OutsideDock)
123
127
                return -1;
124
128
 
125
129
        int index = -1;
136
140
 
137
141
void ScToolBar::storeDockPositions()
138
142
{
139
 
        if (place() == QDockWindow::OutsideDock)
 
143
        if (place() == Q3DockWindow::OutsideDock)
140
144
                return; // nothing to store if not docked
141
 
        QPtrList<QDockWindow> tbs = area()->dockWindowList();
142
 
        for (uint i = 0; i < tbs.count(); ++i)
 
145
        QList<Q3DockWindow*> tbs = area()->dockWindowList();
 
146
        for (int i = 0; i < tbs.count(); ++i)
143
147
        {
144
148
                if (ScToolBar *sctb = dynamic_cast<ScToolBar*>(tbs.at(i)))
145
149
                        sctb->storeDockPosition();
148
152
 
149
153
void ScToolBar::moveDocks()
150
154
{
151
 
        if (place() == QDockWindow::OutsideDock)
 
155
        if (place() == Q3DockWindow::OutsideDock)
152
156
                return; // do not move if not docked;
153
 
        QPtrList<QDockWindow> tbs = area()->dockWindowList();
154
 
        for (uint i = 0; i < tbs.count(); ++i)
 
157
        QList<Q3DockWindow*> tbs = area()->dockWindowList();
 
158
        for (int i = 0; i < tbs.count(); ++i)
155
159
        {
156
160
                if (ScToolBar *sctb = dynamic_cast<ScToolBar*>(tbs.at(i)))
157
161
                        sctb->moveDock();
160
164
 
161
165
void ScToolBar::moveDock()
162
166
{
163
 
        if (place() == QDockWindow::OutsideDock)
 
167
        if (place() == Q3DockWindow::OutsideDock)
164
168
                return; // do not move if not docked
165
169
        area()->moveDockWindow(this, m_prefs->getInt("PosIndex", -1));
166
170
        setOffset(m_prefs->getInt("Offset", 0));
167
171
}
168
172
 
169
 
void ScToolBar::slotPlaceChanged(QDockWindow::Place p)
 
173
void ScToolBar::slotPlaceChanged(Q3DockWindow::Place p)
170
174
{
171
 
        m_prefs->set("IsDocked", p == QDockWindow::InDock);
 
175
        m_prefs->set("IsDocked", p == Q3DockWindow::InDock);
172
176
        m_prefs->set("x", x());
173
177
        m_prefs->set("y", y());
174
 
        if (p == QDockWindow::InDock) {
 
178
        if (p == Q3DockWindow::InDock) {
175
179
                setOrientation(area()->orientation());
176
180
                QString dockPlace = "top";
177
181
                if (area() == mainWindow()->leftDock())
196
200
void ScToolBar::slotTop()
197
201
{
198
202
        dockTop = !dockTop;
199
 
        mainWindow()->setDockEnabled(this, DockTop, dockTop);
 
203
        mainWindow()->setDockEnabled(this, Qt::DockTop, dockTop);
200
204
        dockMenu->setItemChecked(dockMenu->idAt(0), dockTop);
201
205
        m_prefs->set("DockTop", dockTop);
202
206
        if (place() == InDock && mainWindow()->topDock() == area())
206
210
void ScToolBar::slotRight()
207
211
{
208
212
        dockRight = !dockRight;
209
 
        mainWindow()->setDockEnabled(this, DockRight, dockRight);
 
213
        mainWindow()->setDockEnabled(this, Qt::DockRight, dockRight);
210
214
        dockMenu->setItemChecked(dockMenu->idAt(1), dockRight);
211
215
        m_prefs->set("DockRight", dockRight);
212
216
        if (place() == InDock && mainWindow()->rightDock() == area())
216
220
void ScToolBar::slotBottom()
217
221
{
218
222
        dockBottom = !dockBottom;
219
 
        mainWindow()->setDockEnabled(this, DockBottom, dockBottom);
 
223
        mainWindow()->setDockEnabled(this, Qt::DockBottom, dockBottom);
220
224
        dockMenu->setItemChecked(dockMenu->idAt(2), dockBottom);
221
225
        m_prefs->set("DockBottom", dockBottom);
222
226
        if (place() == InDock && mainWindow()->bottomDock() == area())
226
230
void ScToolBar::slotLeft()
227
231
{
228
232
        dockLeft = !dockLeft;
229
 
        mainWindow()->setDockEnabled(this, DockLeft, dockLeft);
 
233
        mainWindow()->setDockEnabled(this, Qt::DockLeft, dockLeft);
230
234
        dockMenu->setItemChecked(dockMenu->idAt(3), dockLeft);
231
235
        m_prefs->set("DockLeft", dockLeft);
232
236
        if (place() == InDock && mainWindow()->leftDock() == area())
235
239
 
236
240
void ScToolBar::slotVert()
237
241
{
238
 
        floatOrientation = QDockWindow::Vertical;
 
242
        floatOrientation = Qt::Vertical;
239
243
        orientationMenu->setItemChecked(orientationMenu->idAt(0), false);
240
244
        orientationMenu->setItemChecked(orientationMenu->idAt(1), true);
241
245
        m_prefs->set("FloatOrientation", Vert);
245
249
 
246
250
void ScToolBar::slotHor()
247
251
{
248
 
        floatOrientation = QDockWindow::Horizontal;
 
252
        floatOrientation = Qt::Horizontal;
249
253
        orientationMenu->setItemChecked(orientationMenu->idAt(0), true);
250
254
        orientationMenu->setItemChecked(orientationMenu->idAt(1), false);
251
255
        m_prefs->set("FloatOrientation", Hor);
252
256
        if (place() != InDock)
253
257
                setOrientation(floatOrientation);
254
258
}
255
 
 
 
259
*/
256
260
void ScToolBar::languageChange()
257
261
{
258
 
        popup->clear();
259
 
 
260
 
        dockMenu = new QPopupMenu(0, "dockMenu");
261
 
        dockMenu->setCheckable(true);
262
 
        dockMenu->insertItem( tr("Top"), this, SLOT(slotTop()));
263
 
        dockMenu->insertItem( tr("Right"), this, SLOT(slotRight()));
264
 
        dockMenu->insertItem( tr("Bottom"), this, SLOT(slotBottom()));
265
 
        dockMenu->insertItem( tr("Left"), this, SLOT(slotLeft()));
266
 
        popup->insertItem( tr("Allow Docking To..."), dockMenu);
267
 
        dockMenu->setItemChecked(dockMenu->idAt(0), dockTop);
268
 
        dockMenu->setItemChecked(dockMenu->idAt(1), dockRight);
269
 
        dockMenu->setItemChecked(dockMenu->idAt(2), dockBottom);
270
 
        dockMenu->setItemChecked(dockMenu->idAt(3), dockLeft);
271
 
 
272
 
        orientationMenu = new QPopupMenu(0, "orientationMenu");
273
 
        orientationMenu->setCheckable(true);
274
 
        orientationMenu->insertItem( tr("Horizontal"), this, SLOT(slotHor()));
275
 
        orientationMenu->insertItem( tr("Vertical"), this, SLOT(slotVert()));
276
 
        popup->insertItem( tr("Floating Orientation..."), orientationMenu);
277
 
        if (floatOrientation == QDockWindow::Horizontal)
278
 
        {
279
 
                orientationMenu->setItemChecked(orientationMenu->idAt(0), true);
280
 
                orientationMenu->setItemChecked(orientationMenu->idAt(1), false);
281
 
        }
282
 
        else
283
 
        {
284
 
                orientationMenu->setItemChecked(orientationMenu->idAt(0), false);
285
 
                orientationMenu->setItemChecked(orientationMenu->idAt(1), true);
286
 
        }
287
 
}
288
 
 
289
 
void ScToolBar::initPrefsButton()
290
 
{
291
 
        prefsButton = new QToolButton(Qt::DownArrow, this, "tbprefsbutton");
292
 
        prefsButton->setAutoRaise(true);
293
 
        popup = new QPopupMenu(0, "prefspopup");
294
 
        prefsButton->setPopup(popup);
295
 
        prefsButton->setPopupDelay(1);
296
 
}
 
262
//      popup->clear();
 
263
 
 
264
//      dockMenu = new QMenu(0);
 
265
//      dockMenu->setCheckable(true);
 
266
//      dockMenu->insertItem( tr("Top"), this, SLOT(slotTop()));
 
267
//      dockMenu->insertItem( tr("Right"), this, SLOT(slotRight()));
 
268
//      dockMenu->insertItem( tr("Bottom"), this, SLOT(slotBottom()));
 
269
//      dockMenu->insertItem( tr("Left"), this, SLOT(slotLeft()));
 
270
//      popup->insertItem( tr("Allow Docking To..."), dockMenu);
 
271
//      dockMenu->setItemChecked(dockMenu->idAt(0), dockTop);
 
272
//      dockMenu->setItemChecked(dockMenu->idAt(1), dockRight);
 
273
//      dockMenu->setItemChecked(dockMenu->idAt(2), dockBottom);
 
274
//      dockMenu->setItemChecked(dockMenu->idAt(3), dockLeft);
 
275
// 
 
276
//      orientationMenu = new QMenu(0);
 
277
//      orientationMenu->setCheckable(true);
 
278
//      orientationMenu->insertItem( tr("Horizontal"), this, SLOT(slotHor()));
 
279
//      orientationMenu->insertItem( tr("Vertical"), this, SLOT(slotVert()));
 
280
//      popup->insertItem( tr("Floating Orientation..."), orientationMenu);
 
281
//      bool b=(floatOrientation == Qt::Horizontal);
 
282
//      orientationMenu->setItemChecked(orientationMenu->idAt(0), b);
 
283
//      orientationMenu->setItemChecked(orientationMenu->idAt(1), !b);
 
284
}
 
285
 
 
286
// void ScToolBar::initPrefsButton()
 
287
// {
 
288
//      prefsButton = new QToolButton(Qt::DownArrow, this, "tbprefsbutton");
 
289
//      prefsButton->setAutoRaise(true);
 
290
//      popup = new QMenu(0);
 
291
//      prefsButton->setPopup(popup);
 
292
//      prefsButton->setPopupDelay(1);
 
293
// }
297
294
 
298
295
ScToolBar::~ScToolBar()
299
296
{
300
297
 
301
298
}
 
299
 
 
300
void ScToolBar::hideEvent(QHideEvent * e)
 
301
{
 
302
        emit visibilityChanged(isVisible());
 
303
        QToolBar::hideEvent(e);
 
304
}
 
305
 
 
306
void ScToolBar::showEvent(QShowEvent * e)
 
307
{
 
308
        emit visibilityChanged(isVisible());
 
309
        QToolBar::showEvent(e);
 
310
}