| 1 | #include "toolbardlg.h"
|
|---|
| 2 |
|
|---|
| 3 | #include "psicon.h"
|
|---|
| 4 | #include "common.h"
|
|---|
| 5 | #include "iconwidget.h"
|
|---|
| 6 | #include "mainwin.h"
|
|---|
| 7 | #include "psitoolbar.h"
|
|---|
| 8 | #include "iconaction.h"
|
|---|
| 9 | #include "psiactionlist.h"
|
|---|
| 10 |
|
|---|
| 11 | #include "opt_lookfeel_toolbars.h"
|
|---|
| 12 | #include "ui_positiontoolbar.h"
|
|---|
| 13 |
|
|---|
| 14 | #include <qlayout.h>
|
|---|
| 15 | #include <qpushbutton.h>
|
|---|
| 16 | #include <qframe.h>
|
|---|
| 17 | #include <qlistview.h>
|
|---|
| 18 | #include <qcombobox.h>
|
|---|
| 19 | #include <qaction.h>
|
|---|
| 20 | #include <qlineedit.h>
|
|---|
| 21 | #include <qcheckbox.h>
|
|---|
| 22 | #include <qheader.h>
|
|---|
| 23 | #include <qspinbox.h>
|
|---|
| 24 |
|
|---|
| 25 | //----------------------------------------------------------------------------
|
|---|
| 26 | // PositionToolbarDlg
|
|---|
| 27 | //----------------------------------------------------------------------------
|
|---|
| 28 |
|
|---|
| 29 | class PositionToolbarDlg : public PositionToolbarUI
|
|---|
| 30 | {
|
|---|
| 31 | Q_OBJECT
|
|---|
| 32 | public:
|
|---|
| 33 | PositionToolbarDlg(QWidget *parent, Options::ToolbarPrefs *, int);
|
|---|
| 34 | ~PositionToolbarDlg();
|
|---|
| 35 |
|
|---|
| 36 | int n();
|
|---|
| 37 | bool dirty;
|
|---|
| 38 |
|
|---|
| 39 | bool eventFilter(QObject *watched, QEvent *e);
|
|---|
| 40 |
|
|---|
| 41 | signals:
|
|---|
| 42 | void applyPressed();
|
|---|
| 43 |
|
|---|
| 44 | private slots:
|
|---|
| 45 | void dataChanged();
|
|---|
| 46 | void apply();
|
|---|
| 47 |
|
|---|
| 48 | private:
|
|---|
| 49 | int id;
|
|---|
| 50 | Options::ToolbarPrefs *tb;
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 | PositionToolbarDlg::PositionToolbarDlg(QWidget *parent, Options::ToolbarPrefs *_tb, int _id)
|
|---|
| 54 | : PositionToolbarUI(parent, "PositionToolbarDlg", true)
|
|---|
| 55 | {
|
|---|
| 56 | tb = _tb;
|
|---|
| 57 | id = _id;
|
|---|
| 58 |
|
|---|
| 59 | connect(pb_ok, SIGNAL(clicked()), SLOT(apply()));
|
|---|
| 60 | connect(pb_ok, SIGNAL(clicked()), SLOT(accept()));
|
|---|
| 61 | connect(pb_apply, SIGNAL(clicked()), SLOT(apply()));
|
|---|
| 62 | connect(pb_cancel, SIGNAL(clicked()), SLOT(reject()));
|
|---|
| 63 |
|
|---|
| 64 | connect(cb_dock, SIGNAL(highlighted(int)), SLOT(dataChanged()));
|
|---|
| 65 | sb_index->installEventFilter( this );
|
|---|
| 66 | sb_extraOffset->installEventFilter( this );
|
|---|
| 67 | connect(ck_nl, SIGNAL(toggled(bool)), SLOT(dataChanged()));
|
|---|
| 68 |
|
|---|
| 69 | le_name->setText( tb->name );
|
|---|
| 70 | if ( tb->dock >= DockUnmanaged && tb->dock <= DockTornOff ) {
|
|---|
| 71 | cb_dock->setCurrentItem( tb->dock + DockMinimized - DockTornOff );
|
|---|
| 72 | }
|
|---|
| 73 | else {
|
|---|
| 74 | cb_dock->setCurrentItem( tb->dock - DockTop );
|
|---|
| 75 | }
|
|---|
| 76 | sb_index->setValue( tb->index );
|
|---|
| 77 | sb_extraOffset->setValue( tb->extraOffset );
|
|---|
| 78 | ck_nl->setChecked( tb->nl );
|
|---|
| 79 |
|
|---|
| 80 | dirty = false;
|
|---|
| 81 | pb_apply->setEnabled(false);
|
|---|
| 82 |
|
|---|
| 83 | resize(sizeHint());
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | PositionToolbarDlg::~PositionToolbarDlg()
|
|---|
| 87 | {
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | int PositionToolbarDlg::n()
|
|---|
| 91 | {
|
|---|
| 92 | return id;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | void PositionToolbarDlg::dataChanged()
|
|---|
| 96 | {
|
|---|
| 97 | dirty = true;
|
|---|
| 98 | pb_apply->setEnabled(true);
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | void PositionToolbarDlg::apply()
|
|---|
| 102 | {
|
|---|
| 103 | tb->dirty = true;
|
|---|
| 104 | if ( cb_dock->currentItem() >= 0 && cb_dock->currentItem() < 5 ) {
|
|---|
| 105 | // Top, Bottom, Left, Right and Minimised
|
|---|
| 106 | tb->dock = (Dock)(cb_dock->currentItem() + DockTop);
|
|---|
| 107 | }
|
|---|
| 108 | else {
|
|---|
| 109 | // Unmanaged and TornOff
|
|---|
| 110 | tb->dock = (Dock)(cb_dock->currentItem() - (DockMinimized - DockTornOff));
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | tb->index = sb_index->value();
|
|---|
| 114 | tb->extraOffset = sb_extraOffset->value();
|
|---|
| 115 | tb->nl = ck_nl->isChecked();
|
|---|
| 116 |
|
|---|
| 117 | if ( dirty )
|
|---|
| 118 | emit applyPressed();
|
|---|
| 119 | dirty = false;
|
|---|
| 120 | pb_apply->setEnabled(false);
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | bool PositionToolbarDlg::eventFilter(QObject *watched, QEvent *e)
|
|---|
| 124 | {
|
|---|
| 125 | if ( watched->inherits("QSpinBox") && e->type() == QEvent::KeyRelease )
|
|---|
| 126 | dataChanged();
|
|---|
| 127 | return false;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | //----------------------------------------------------------------------------
|
|---|
| 131 | // ToolbarDlg
|
|---|
| 132 | //----------------------------------------------------------------------------
|
|---|
| 133 |
|
|---|
| 134 | class ToolbarDlg::Private
|
|---|
| 135 | {
|
|---|
| 136 | public:
|
|---|
| 137 | struct ToolbarItem {
|
|---|
| 138 | QString group;
|
|---|
| 139 | int index;
|
|---|
| 140 | ToolbarItem() {
|
|---|
| 141 | group = "";
|
|---|
| 142 | index = -1;
|
|---|
| 143 | }
|
|---|
| 144 | ToolbarItem( QString _w, int _i ) {
|
|---|
| 145 | group = _w;
|
|---|
| 146 | index = _i;
|
|---|
| 147 | }
|
|---|
| 148 | };
|
|---|
| 149 |
|
|---|
| 150 | QMap<int, ToolbarItem> toolbars;
|
|---|
| 151 |
|
|---|
| 152 | PsiActionList::ActionsType class2id( QString name ) {
|
|---|
| 153 | int ret = (int)PsiActionList::Actions_Common;
|
|---|
| 154 |
|
|---|
| 155 | if ( name == "mainWin" )
|
|---|
| 156 | ret |= (int)PsiActionList::Actions_MainWin;
|
|---|
| 157 |
|
|---|
| 158 | return (PsiActionList::ActionsType)ret;
|
|---|
| 159 | }
|
|---|
| 160 | };
|
|---|
| 161 |
|
|---|
| 162 | ToolbarDlg::ToolbarDlg(PsiCon *_psi, QWidget *parent, const char *name)
|
|---|
| 163 | : QDialog(parent, name, false, WDestructiveClose)
|
|---|
| 164 | {
|
|---|
| 165 | p = new Private();
|
|---|
| 166 |
|
|---|
| 167 | psi = _psi;
|
|---|
| 168 | psi->dialogRegister(this);
|
|---|
| 169 | noDirty = false;
|
|---|
| 170 | opt = new Options;
|
|---|
| 171 |
|
|---|
| 172 | setCaption(CAP(tr("Configure Toolbars")));
|
|---|
| 173 |
|
|---|
| 174 | connect(this, SIGNAL(dataChanged()), SLOT(dataChangedSlot()));
|
|---|
| 175 |
|
|---|
| 176 | QVBoxLayout *vbox = new QVBoxLayout(this, 11, 6);
|
|---|
| 177 | w = new LookFeelToolbarsUI(this);
|
|---|
| 178 | vbox->addWidget(w);
|
|---|
| 179 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
|---|
| 180 |
|
|---|
| 181 | connect(d->pb_addToolbar, SIGNAL(clicked()), SLOT(toolbarAdd()));
|
|---|
| 182 | connect(d->pb_deleteToolbar, SIGNAL(clicked()), SLOT(toolbarDelete()));
|
|---|
| 183 | connect(d->cb_toolbars, SIGNAL(activated(int)), SLOT(toolbarSelectionChanged(int)));
|
|---|
| 184 | connect(d->le_toolbarName, SIGNAL(textChanged(const QString &)), SLOT(toolbarNameChanged()));
|
|---|
| 185 | connect(d->pb_toolbarPosition, SIGNAL(clicked()), SLOT(toolbarPosition()));
|
|---|
| 186 | connect(d->tb_up, SIGNAL(clicked()), SLOT(toolbarActionUp()));
|
|---|
| 187 | connect(d->tb_down, SIGNAL(clicked()), SLOT(toolbarActionDown()));
|
|---|
| 188 | connect(d->tb_right, SIGNAL(clicked()), SLOT(toolbarAddAction()));
|
|---|
| 189 | connect(d->tb_left, SIGNAL(clicked()), SLOT(toolbarRemoveAction()));
|
|---|
| 190 |
|
|---|
| 191 | connect(d->ck_toolbarOn, SIGNAL(toggled(bool)), SLOT(toolbarDataChanged()));
|
|---|
| 192 | connect(d->ck_toolbarLocked, SIGNAL(toggled(bool)), SLOT(toolbarDataChanged()));
|
|---|
| 193 | connect(d->ck_toolbarStretch, SIGNAL(toggled(bool)), SLOT(toolbarDataChanged()));
|
|---|
| 194 | connect(d->lv_selectedActions, SIGNAL(selectionChanged(QListViewItem *)), SLOT(selAct_selectionChanged(QListViewItem *)));
|
|---|
| 195 | connect(d->lv_availActions, SIGNAL(selectionChanged(QListViewItem *)), SLOT(avaAct_selectionChanged(QListViewItem *)));
|
|---|
| 196 |
|
|---|
| 197 | connect(d->pb_deleteToolbar, SIGNAL(clicked()), SIGNAL(dataChanged()));
|
|---|
| 198 | connect(d->tb_up, SIGNAL(clicked()), SIGNAL(dataChanged()));
|
|---|
| 199 | connect(d->tb_down, SIGNAL(clicked()), SIGNAL(dataChanged()));
|
|---|
| 200 | connect(d->tb_left, SIGNAL(clicked()), SIGNAL(dataChanged()));
|
|---|
| 201 | connect(d->tb_right, SIGNAL(clicked()), SIGNAL(dataChanged()));
|
|---|
| 202 | connect(d->pb_addToolbar, SIGNAL(clicked()), SIGNAL(dataChanged()));
|
|---|
| 203 | connect(d->pb_deleteToolbar, SIGNAL(clicked()), SIGNAL(dataChanged()));
|
|---|
| 204 |
|
|---|
| 205 | d->lv_selectedActions->header()->hide();
|
|---|
| 206 | d->lv_availActions->header()->hide();
|
|---|
| 207 |
|
|---|
| 208 | d->lv_selectedActions->setSorting(-1);
|
|---|
| 209 | d->lv_availActions->setSorting(-1);
|
|---|
| 210 |
|
|---|
| 211 | // TODO: add QWhatsThis to all widgets
|
|---|
| 212 |
|
|---|
| 213 | QFrame *line = new QFrame( this );
|
|---|
| 214 | line->setFrameShape( QFrame::HLine );
|
|---|
| 215 | line->setFrameShadow( QFrame::Sunken );
|
|---|
| 216 | line->setFrameShape( QFrame::HLine );
|
|---|
| 217 | vbox->addWidget( line );
|
|---|
| 218 |
|
|---|
| 219 | QHBoxLayout *hbox = new QHBoxLayout( 0, 0, 6 );
|
|---|
| 220 | vbox->addLayout(hbox);
|
|---|
| 221 |
|
|---|
| 222 | QSpacerItem *spacer = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
|
|---|
| 223 | hbox->addItem( spacer );
|
|---|
| 224 |
|
|---|
| 225 | IconButton *pb_ok = new IconButton( this );
|
|---|
| 226 | hbox->addWidget( pb_ok );
|
|---|
|
|---|