Changeset 128 for smplayer/trunk/src/toolbareditor.cpp
- Timestamp:
- Mar 29, 2012, 4:53:15 PM (13 years ago)
- Location:
- smplayer/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/trunk
- Property svn:mergeinfo changed
/smplayer/vendor/current merged: 127
- Property svn:mergeinfo changed
-
smplayer/trunk/src/toolbareditor.cpp
r124 r128 21 21 #include <QToolBar> 22 22 #include <QToolButton> 23 #include <QMatrix> 24 25 #include "images.h" 26 27 ToolbarEditor::ToolbarEditor( QWidget* parent, Qt::WindowFlags f ) 28 : QDialog(parent, f) 29 { 30 setupUi(this); 31 32 up_button->setIcon(Images::icon("up")); 33 down_button->setIcon(Images::icon("down")); 34 35 QMatrix matrix; 36 matrix.rotate(90); 37 38 right_button->setIcon( Images::icon("up").transformed(matrix) ); 39 left_button->setIcon( Images::icon("down").transformed(matrix) ); 40 41 QPushButton * restore = buttonBox->button(QDialogButtonBox::RestoreDefaults); 42 connect(restore, SIGNAL(clicked()), this, SLOT(restoreDefaults())); 43 44 connect(all_actions_list, SIGNAL(currentRowChanged(int)), 45 this, SLOT(checkRowsAllList(int))); 46 connect(active_actions_list, SIGNAL(currentRowChanged(int)), 47 this, SLOT(checkRowsActiveList(int))); 48 49 #if QT_VERSION >= 0x040600 50 all_actions_list->setSelectionMode(QAbstractItemView::SingleSelection); 51 all_actions_list->setDragEnabled(true); 52 all_actions_list->viewport()->setAcceptDrops(true); 53 all_actions_list->setDropIndicatorShown(true); 54 all_actions_list->setDefaultDropAction(Qt::MoveAction); // Qt 4.6 55 //all_actions_list->setDragDropMode(QAbstractItemView::InternalMove); 56 57 active_actions_list->setSelectionMode(QAbstractItemView::SingleSelection); 58 active_actions_list->setDragEnabled(true); 59 active_actions_list->viewport()->setAcceptDrops(true); 60 active_actions_list->setDropIndicatorShown(true); 61 active_actions_list->setDefaultDropAction(Qt::MoveAction); // Qt 4.6 62 //active_actions_list->setDragDropMode(QAbstractItemView::InternalMove); 63 #endif 64 } 65 66 ToolbarEditor::~ToolbarEditor() { 67 } 68 69 void ToolbarEditor::populateList(QListWidget * w, QList<QAction *> actions_list, bool add_separators) { 70 w->clear(); 71 72 QAction * action; 73 for (int n = 0; n < actions_list.count(); n++) { 74 action = static_cast<QAction*> (actions_list[n]); 75 if (action) { 76 if (!action->objectName().isEmpty()) { 77 QListWidgetItem * i = new QListWidgetItem; 78 QString text = fixname(action->text(), action->objectName()); 79 i->setText(text + " ("+ action->objectName() +")"); 80 i->setIcon(action->icon()); 81 i->setData(Qt::UserRole, action->objectName()); 82 w->addItem(i); 83 } 84 else 85 if ((action->isSeparator()) && (add_separators)) { 86 QListWidgetItem * i = new QListWidgetItem; 87 i->setText(tr("(separator)")); 88 i->setData(Qt::UserRole, "separator"); 89 w->addItem(i); 90 } 91 } 92 } 93 } 94 95 void ToolbarEditor::setAllActions(QList<QAction *> actions_list) { 96 populateList(all_actions_list, actions_list, false); 97 all_actions_copy = actions_list; 98 } 99 100 void ToolbarEditor::setActiveActions(QList<QAction *> actions_list) { 101 populateList(active_actions_list, actions_list, true); 102 103 // Delete actions from the "all list" which are in the active list 104 for (int n = 0; n < active_actions_list->count(); n++) { 105 int row = findItem( active_actions_list->item(n)->data(Qt::UserRole).toString(), all_actions_list ); 106 if (row > -1) { 107 qDebug("found: %s", active_actions_list->item(n)->data(Qt::UserRole).toString().toUtf8().constData()); 108 all_actions_list->takeItem(row); 109 } 110 } 111 } 112 113 int ToolbarEditor::findItem(const QString & action_name, QListWidget * w) { 114 for (int n = 0; n < w->count(); n++) { 115 if (w->item(n)->data(Qt::UserRole).toString() == action_name) { 116 return n; 117 } 118 } 119 return -1; 120 } 121 122 void ToolbarEditor::on_up_button_clicked() { 123 int row = active_actions_list->currentRow(); 124 qDebug("ToolbarEditor::on_up_button_clicked: current_row: %d", row); 125 126 if (row == 0) return; 127 128 QListWidgetItem * current = active_actions_list->takeItem(row); 129 active_actions_list->insertItem(row-1, current); 130 active_actions_list->setCurrentRow(row-1); 131 } 132 133 void ToolbarEditor::on_down_button_clicked() { 134 int row = active_actions_list->currentRow(); 135 qDebug("ToolbarEditor::on_down_button_clicked: current_row: %d", row); 136 137 if ((row+1) >= active_actions_list->count()) return; 138 139 QListWidgetItem * current = active_actions_list->takeItem(row); 140 active_actions_list->insertItem(row+1, current); 141 active_actions_list->setCurrentRow(row+1); 142 } 143 144 void ToolbarEditor::on_right_button_clicked() { 145 int row = all_actions_list->currentRow(); 146 qDebug("ToolbarEditor::on_right_button_clicked: current_row: %d", row); 147 148 if (row > -1) { 149 QListWidgetItem * current = all_actions_list->takeItem(row); 150 int dest_row = active_actions_list->currentRow(); 151 if (dest_row > -1) { 152 active_actions_list->insertItem(dest_row+1, current); 153 } else { 154 active_actions_list->addItem(current); 155 } 156 } 157 } 158 159 void ToolbarEditor::on_left_button_clicked() { 160 int row = active_actions_list->currentRow(); 161 qDebug("ToolbarEditor::on_left_button_clicked: current_row: %d", row); 162 163 if (row > -1) { 164 QListWidgetItem * current = active_actions_list->takeItem(row); 165 if (current->data(Qt::UserRole).toString() != "separator") { 166 int dest_row = all_actions_list->currentRow(); 167 if (dest_row > -1) { 168 all_actions_list->insertItem(dest_row+1, current); 169 } else { 170 all_actions_list->addItem(current); 171 } 172 } 173 } 174 } 175 176 void ToolbarEditor::on_separator_button_clicked() { 177 qDebug("ToolbarEditor::on_separator_button_clicked"); 178 179 QListWidgetItem * i = new QListWidgetItem; 180 i->setText(tr("(separator)")); 181 i->setData(Qt::UserRole, "separator"); 182 183 int row = active_actions_list->currentRow(); 184 if (row > -1) { 185 active_actions_list->insertItem(row+1, i); 186 } else { 187 active_actions_list->addItem(i); 188 } 189 } 190 191 void ToolbarEditor::restoreDefaults() { 192 qDebug("ToolbarEditor::restoreDefaults"); 193 populateList(all_actions_list, all_actions_copy, false); 194 195 // Create list of actions 196 QList<QAction *> actions; 197 QAction * a = 0; 198 for (int n = 0; n < default_actions.count(); n++) { 199 if (default_actions[n] == "separator") { 200 QAction * sep = new QAction(this); 201 sep->setSeparator(true); 202 actions.push_back(sep); 203 } else { 204 a = findAction(default_actions[n], all_actions_copy); 205 if (a) actions.push_back(a); 206 } 207 } 208 setActiveActions(actions); 209 } 210 211 QStringList ToolbarEditor::activeActionsToStringList() { 212 QStringList o; 213 for (int n = 0; n < active_actions_list->count(); n++) { 214 o << active_actions_list->item(n)->data(Qt::UserRole).toString(); 215 } 216 return o; 217 } 218 219 void ToolbarEditor::checkRowsAllList(int currentRow) { 220 qDebug("ToolbarEditor::checkRowsAllList: current row: %d", currentRow); 221 right_button->setEnabled(currentRow > -1); 222 } 223 224 void ToolbarEditor::checkRowsActiveList(int currentRow) { 225 qDebug("ToolbarEditor::checkRowsActiveList: current row: %d", currentRow); 226 left_button->setEnabled(currentRow > -1); 227 if (currentRow == -1) { 228 up_button->setEnabled(false); 229 down_button->setEnabled(false); 230 } else { 231 up_button->setEnabled((currentRow > 0)); 232 down_button->setEnabled((currentRow < active_actions_list->count()-1)); 233 } 234 } 235 236 QString ToolbarEditor::fixname(const QString & name, const QString & action_name) { 237 QString s = name; 238 s = s.replace("&", ""); 239 if (action_name == "timeslider_action") s = tr("Time slider"); 240 else 241 if (action_name == "volumeslider_action") s = tr("Volume slider"); 242 else 243 if (action_name == "timelabel_action") s = tr("Display time"); 244 else 245 if (action_name == "rewindbutton_action") s = tr("3 in 1 rewind"); 246 else 247 if (action_name == "forwardbutton_action") s = tr("3 in 1 forward"); 248 return s; 249 } 23 250 24 251 QStringList ToolbarEditor::save(QWidget * w) { … … 93 320 } 94 321 322 #include "moc_toolbareditor.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.