24
24
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25
25
***************************************************************************/
31
#include <QToolButton>
27
33
#include "sctoolbar.h"
28
#include "sctoolbar.moc"
29
35
#include "prefscontext.h"
30
36
#include "prefsfile.h"
31
37
#include "prefsmanager.h"
33
#include <qdockarea.h>
34
#include <qdockwindow.h>
35
#include <qmainwindow.h>
37
#include <qtoolbutton.h>
38
#include <qpopupmenu.h>
40
extern QPixmap loadIcon(QString nam);
42
ScToolBar::ScToolBar(const QString& name, const QString &prefName, QMainWindow *parent, QDockWindow::Orientation o)
38
#include "util_icon.h"
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))
48
setCloseMode(QDockWindow::Undocked);
49
setAllowedAreas(Qt::AllToolBarAreas);
50
this->setIconSize(QSize(16,16));
52
setCloseMode(Q3DockWindow::Undocked);
50
54
if (m_prefs->contains("IsDocked")) // set docking
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);
93
97
if (place() == InDock)
94
98
setOrientation(area()->orientation());
161
165
void ScToolBar::moveDock()
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));
169
void ScToolBar::slotPlaceChanged(QDockWindow::Place p)
173
void ScToolBar::slotPlaceChanged(Q3DockWindow::Place p)
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())
246
250
void ScToolBar::slotHor()
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);
256
260
void ScToolBar::languageChange()
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);
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)
279
orientationMenu->setItemChecked(orientationMenu->idAt(0), true);
280
orientationMenu->setItemChecked(orientationMenu->idAt(1), false);
284
orientationMenu->setItemChecked(orientationMenu->idAt(0), false);
285
orientationMenu->setItemChecked(orientationMenu->idAt(1), true);
289
void ScToolBar::initPrefsButton()
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);
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);
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);
286
// void ScToolBar::initPrefsButton()
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);
298
295
ScToolBar::~ScToolBar()
300
void ScToolBar::hideEvent(QHideEvent * e)
302
emit visibilityChanged(isVisible());
303
QToolBar::hideEvent(e);
306
void ScToolBar::showEvent(QShowEvent * e)
308
emit visibilityChanged(isVisible());
309
QToolBar::showEvent(e);