Subversion Repositories Scribus

Rev

Rev 14509 | Rev 16546 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
1111 tsoots 7
/***************************************************************************
8
 *   Copyright (C) 2005 by Riku Leino                                      *
9
 *   tsoots@gmail.com                                                      *
10
 *                                                                         *
11
 *   This program is free software; you can redistribute it and/or modify  *
12
 *   it under the terms of the GNU General Public License as published by  *
13
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 *   (at your option) any later version.                                   *
15
 *                                                                         *
16
 *   This program is distributed in the hope that it will be useful,       *
17
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19
 *   GNU General Public License for more details.                          *
20
 *                                                                         *
21
 *   You should have received a copy of the GNU General Public License     *
22
 *   along with this program; if not, write to the                         *
23
 *   Free Software Foundation, Inc.,                                       *
24
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
25
 ***************************************************************************/
10859 cbradney 26
#include <QDebug>
27
#include <QEvent>
10223 cbradney 28
#include <QPushButton>
29
#include <QCheckBox>
10192 cbradney 30
#include <QVBoxLayout>
10483 subik 31
 
1288 cbradney 32
#include "undogui.h"
2856 cbradney 33
#include "prefsmanager.h"
5781 cbradney 34
#include "scribuscore.h"
14509 cbradney 35
#include "ui/scmwmenumanager.h"
3251 craig 36
#include "scraction.h"
10200 cbradney 37
#include "util_icon.h"
1111 tsoots 38
 
8501 cbradney 39
UndoGui::UndoGui(QWidget* parent, const char* name, Qt::WFlags f) : ScrPaletteBase(parent, name, f)
1111 tsoots 40
{
41
 
42
}
43
 
44
/*** UndoWidget ***************************************************************/
45
 
46
UndoWidget::UndoWidget(QWidget* parent, const char* name)
47
: UndoGui(parent, name)
48
{
1288 cbradney 49
        /* BnF standard toolbar buttons
1111 tsoots 50
        QHBoxLayout* layout = new QHBoxLayout(this, 0, 0, "layout");
51
 
1288 cbradney 52
 
1111 tsoots 53
        undoButton = new QToolButton(this, "undoButton");
54
        undoButton->setIconSet(loadIcon("u_undo.png"));
55
        undoButton->setUsesTextLabel(false);
10397 cbradney 56
        undoButton->setToolTip(tr("Undo"));
1111 tsoots 57
        layout->addWidget(undoButton);
58
        undoMenu = new QPopupMenu(undoButton, "undoMenu");
59
        undoButton->setPopup(undoMenu);
60
        undoButton->setPopupDelay(0);
1138 tsoots 61
        undoButton->setAutoRaise(true);
1111 tsoots 62
 
63
        redoButton = new QToolButton(this, "redoButton");
64
        redoButton->setIconSet(loadIcon("u_redo.png"));
65
        redoButton->setUsesTextLabel(false);
10397 cbradney 66
        redoButton->setToolTip(tr("Redo"));
1111 tsoots 67
        layout->addWidget(redoButton);
68
        redoMenu = new QPopupMenu(redoButton, "redoMenu");
69
        redoButton->setPopup(redoMenu);
70
        redoButton->setPopupDelay(0);
1138 tsoots 71
        redoButton->setAutoRaise(true);
1288 cbradney 72
        */
73
        //Scribus action based toolbar button construction
9800 cbradney 74
        parent->addAction(ScCore->primaryMainWindow()->scrActions["editUndoAction"]);
75
        parent->addAction(ScCore->primaryMainWindow()->scrActions["editRedoAction"]);
5781 cbradney 76
        ScCore->primaryMainWindow()->scrMenuMgr->createMenu("undoButtonMenu", "undoButtonMenu");
77
        ScCore->primaryMainWindow()->scrMenuMgr->createMenu("redoButtonMenu", "redoButtonMenu");
78
        undoMenu=ScCore->primaryMainWindow()->scrMenuMgr->getLocalPopupMenu("undoButtonMenu");
79
        redoMenu=ScCore->primaryMainWindow()->scrMenuMgr->getLocalPopupMenu("redoButtonMenu");
80
        ScCore->primaryMainWindow()->scrMenuMgr->addMenuToWidgetOfAction("undoButtonMenu", ScCore->primaryMainWindow()->scrActions["editUndoAction"]);
9768 cbradney 81
        ScCore->primaryMainWindow()->scrMenuMgr->addMenuToWidgetOfAction("redoButton/*Menu*/", ScCore->primaryMainWindow()->scrActions["editRedoAction"]);
11292 subik 82
 
9800 cbradney 83
        parent->addAction(ScCore->primaryMainWindow()->scrActions["editCut"]);
84
        parent->addAction(ScCore->primaryMainWindow()->scrActions["editCopy"]);
85
        parent->addAction(ScCore->primaryMainWindow()->scrActions["editPaste"]);
5800 fschmid 86
        ScCore->primaryMainWindow()->scrMenuMgr->addMenuToWidgetOfAction("EditPasteRecent", ScCore->primaryMainWindow()->scrActions["editPaste"]);
11292 subik 87
 
1288 cbradney 88
        /* BnF Undo buttons
1111 tsoots 89
        connect(undoButton, SIGNAL(clicked()), this, SLOT(undoClicked()));
90
        connect(redoButton, SIGNAL(clicked()), this, SLOT(redoClicked()));
1288 cbradney 91
        */
10592 fschmid 92
        connect(undoMenu, SIGNAL(triggered(QAction *)), this, SLOT(undoMenuClicked(QAction *)));
93
        connect(redoMenu, SIGNAL(triggered(QAction *)), this, SLOT(redoMenuClicked(QAction *)));
1111 tsoots 94
}
95
 
96
void UndoWidget::clear()
97
{
98
        undoMenu->clear();
99
        undoItems.clear();
1288 cbradney 100
        //Scribus disable
5781 cbradney 101
        ScCore->primaryMainWindow()->scrActions["editUndoAction"]->setEnabled(false);
1288 cbradney 102
        // BnF disable
103
        //undoButton->setEnabled(false);
1111 tsoots 104
        redoMenu->clear();
105
        redoItems.clear();
1288 cbradney 106
        //Scribus disable;
5781 cbradney 107
        ScCore->primaryMainWindow()->scrActions["editRedoAction"]->setEnabled(false);
1288 cbradney 108
        // BnF disable
109
        //redoButton->setEnabled(false);
1111 tsoots 110
}
111
 
112
void UndoWidget::undoClicked()
113
{
114
        if (undoItems.size() > 0)
115
                emit undo(1);
116
}
117
 
118
void UndoWidget::redoClicked()
119
{
120
        if (redoItems.size() > 0)
121
                emit redo(1);
122
}
123
 
10592 fschmid 124
void UndoWidget::undoMenuClicked(QAction *id)
1111 tsoots 125
{
10592 fschmid 126
        int steps = undoMenu->actions().indexOf(id) + 1;
1111 tsoots 127
        emit undo(steps);
128
}
129
 
10592 fschmid 130
void UndoWidget::redoMenuClicked(QAction *id)
1111 tsoots 131
{
10592 fschmid 132
        int steps = redoMenu->actions().indexOf(id) + 1;
1111 tsoots 133
        emit redo(steps);
134
}
135
 
1336 tsoots 136
void UndoWidget::insertUndoItem(UndoObject* target, UndoState* state)
1111 tsoots 137
{
2397 cbradney 138
        undoItems.insert(undoItems.begin(), QString( tr("%1: %2", "undo target: action (f.e. Text frame: Resize)"))
1336 tsoots 139
                                        .arg(target->getUName()).arg(state->getName()));
1457 tsoots 140
        clearRedo();
1111 tsoots 141
        updateUndoMenu();
1443 tsoots 142
        updateRedoMenu();
1111 tsoots 143
}
144
 
1336 tsoots 145
void UndoWidget::insertRedoItem(UndoObject* target, UndoState* state)
1111 tsoots 146
{
2397 cbradney 147
        redoItems.push_back(QString( tr("%1: %2", "undo target: action (f.e. Text frame: Resize)"))
1336 tsoots 148
                        .arg(target->getUName()).arg(state->getName()));
1111 tsoots 149
        updateRedoMenu();
1443 tsoots 150
        updateUndoMenu();
1111 tsoots 151
}
152
 
1457 tsoots 153
void UndoWidget::clearRedo()
1111 tsoots 154
{
155
        redoItems.erase(redoItems.begin(), redoItems.end());
156
        updateRedoMenu();
157
}
158
 
159
void UndoWidget::updateUndoMenu()
160
{
161
        undoMenu->clear();
162
        for (uint i = 0; i < MENU_HEIGHT && i < undoItems.size(); ++i)
10592 fschmid 163
                undoMenu->addAction(undoItems[i]);
1288 cbradney 164
        //BnF
165
        //undoButton->setEnabled(undoMenu->count() != 0);
166
        //SCribus
4985 cbradney 167
        //ScMW->scrActions["editUndoAction"]->setEnabled(undoMenu->count() != 0);
168
        updateUndoActions();
1111 tsoots 169
}
170
 
171
void UndoWidget::updateRedoMenu()
172
{
173
        redoMenu->clear();
174
        for (uint i = 0; i < MENU_HEIGHT && i < redoItems.size(); ++i)
10592 fschmid 175
                redoMenu->addAction(redoItems[i]);
1288 cbradney 176
        //BnF
177
        //redoButton->setEnabled(redoMenu->count() != 0);
178
        //Scribus
4985 cbradney 179
        //ScMW->scrActions["editRedoAction"]->setEnabled(redoMenu->count() != 0);
180
        updateUndoActions();
181
}
182
 
183
void UndoWidget::updateUndoActions()
184
{
10592 fschmid 185
        ScCore->primaryMainWindow()->scrActions["editUndoAction"]->setEnabled(undoMenu->actions().count() != 0);
186
        ScCore->primaryMainWindow()->scrActions["editRedoAction"]->setEnabled(redoMenu->actions().count() != 0);
1111 tsoots 187
}
188
 
189
void UndoWidget::updateUndo(int steps)
190
{
191
        for (int i = 0; i < steps; ++i)
192
        {
193
                redoItems.insert(redoItems.begin(), undoItems[0]);
11292 subik 194
                undoItems.erase(undoItems.begin());
1111 tsoots 195
        }
196
        updateUndoMenu();
197
        updateRedoMenu();
198
}
199
 
200
void UndoWidget::updateRedo(int steps)
201
{
202
        for (int i = 0; i < steps; ++i)
203
        {
204
                undoItems.insert(undoItems.begin(), redoItems[0]);
11292 subik 205
                redoItems.erase(redoItems.begin());
1111 tsoots 206
        }
207
        updateUndoMenu();
208
        updateRedoMenu();
209
}
210
 
211
void UndoWidget::popBack()
212
{
1197 tsoots 213
        if (undoItems.size() > 0)
214
        {
215
                undoItems.erase(undoItems.end() - 1);
216
                updateUndoMenu();
217
        }
1111 tsoots 218
}
219
 
220
UndoWidget::~UndoWidget()
221
{
11292 subik 222
 
1111 tsoots 223
}
224
 
225
/*** UndoPalette **************************************************************/
226
 
227
UndoPalette::UndoPalette(QWidget* parent, const char* name)
3923 tsoots 228
: UndoGui(parent, name)
1111 tsoots 229
{
230
        currentSelection = 0;
231
        redoItems = 0;
10592 fschmid 232
        QVBoxLayout* layout = new QVBoxLayout(this);
233
        layout->setMargin(5);
234
        layout->setSpacing(5);
235
        objectBox = new QCheckBox(this);
1111 tsoots 236
        layout->addWidget(objectBox);
1443 tsoots 237
//      objectBox->setEnabled(false);
1111 tsoots 238
 
10483 subik 239
        undoList = new QListWidget(this);
240
//      undoList->setMultiSelection(false);
241
//      undoList->setSelectionMode(QListWidget::Single);
242
        undoList->setSelectionMode(QAbstractItemView::SingleSelection);
11292 subik 243
        undoList->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
1111 tsoots 244
        layout->addWidget(undoList);
11292 subik 245
 
10592 fschmid 246
        QHBoxLayout* buttonLayout = new QHBoxLayout;
247
        buttonLayout->setMargin(0);
248
        buttonLayout->setSpacing(5);
249
        undoButton = new QPushButton(loadIcon("16/edit-undo.png"), "", this);
1111 tsoots 250
        buttonLayout->addWidget(undoButton);
10592 fschmid 251
        redoButton = new QPushButton(loadIcon("16/edit-redo.png"), "", this);
2198 cbradney 252
        buttonLayout->addWidget(redoButton);
1441 cbradney 253
        //Save the translated key sequence - hopefully we get the translated one here!
10592 fschmid 254
        initialUndoKS = undoButton->shortcut();
255
        initialRedoKS = redoButton->shortcut();
1111 tsoots 256
        layout->addLayout(buttonLayout);
257
 
1441 cbradney 258
        updateFromPrefs();
2198 cbradney 259
        languageChange();
5257 cbradney 260
        connect(PrefsManager::instance(), SIGNAL(prefsChanged()), this, SLOT(updateFromPrefs()));
1111 tsoots 261
        connect(undoButton, SIGNAL(clicked()), this, SLOT(undoClicked()));
262
        connect(redoButton, SIGNAL(clicked()), this, SLOT(redoClicked()));
10483 subik 263
//      connect(undoList, SIGNAL(highlighted(int)), this, SLOT(undoListClicked(int)));
264
        connect(undoList, SIGNAL(currentRowChanged(int)), this, SLOT(undoListClicked(int)));
265
//      connect(undoList, SIGNAL(onItem(Q3ListBoxItem*)), this, SLOT(showToolTip(Q3ListBoxItem*)));
266
        connect(undoList, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(showToolTip(QListWidgetItem*)));
267
//      connect(undoList, SIGNAL(onViewport()), this, SLOT(removeToolTip()));
268
        connect(undoList, SIGNAL(viewportEntered()), this, SLOT(removeToolTip()));
1443 tsoots 269
        connect(objectBox, SIGNAL(toggled(bool)), this, SLOT(objectCheckBoxClicked(bool)));
5781 cbradney 270
        connect(ScCore->primaryMainWindow()->scrActions["editActionMode"], SIGNAL(toggled(bool)),
1446 tsoots 271
                objectBox, SLOT(setChecked(bool)));
11292 subik 272
        connect(objectBox, SIGNAL(toggled(bool)),
10581 cbradney 273
                        ScCore->primaryMainWindow()->scrActions["editActionMode"], SLOT(setChecked(bool)));
1111 tsoots 274
}
275
 
276
void UndoPalette::clear()
277
{
10987 subik 278
//      qDebug() << "UndoPalette::clear start";
10546 subik 279
        disconnect(undoList, SIGNAL(currentRowChanged(int)), this, SLOT(undoListClicked(int)));
1111 tsoots 280
        undoList->clear();
10483 subik 281
        undoList->addItem( tr("Initial State"));
1111 tsoots 282
        undoButton->setEnabled(false);
283
        redoButton->setEnabled(false);
10546 subik 284
        connect(undoList, SIGNAL(currentRowChanged(int)), this, SLOT(undoListClicked(int)));
10987 subik 285
//      qDebug() << "UndoPalette::clear end";
1111 tsoots 286
}
287
 
1441 cbradney 288
void UndoPalette::updateFromPrefs()
289
{
10987 subik 290
//      qDebug() << "UndoPalette::updateFromPrefs start";
10592 fschmid 291
        undoButton->setShortcut(ScCore->primaryMainWindow()->scrActions["editUndoAction"]->shortcut());
292
        redoButton->setShortcut(ScCore->primaryMainWindow()->scrActions["editRedoAction"]->shortcut());
10987 subik 293
//      qDebug() << "UndoPalette::updateFromPrefs end";
1441 cbradney 294
}
295
 
10859 cbradney 296
void UndoPalette::changeEvent(QEvent *e)
297
{
298
        if (e->type() == QEvent::LanguageChange)
299
        {
300
                languageChange();
301
        }
10903 cbradney 302
        else
303
                QWidget::changeEvent(e);
10859 cbradney 304
}
305
 
2198 cbradney 306
void UndoPalette::languageChange()
307
{
11292 subik 308
        setWindowTitle( tr("Action History"));
13032 cbradney 309
        objectBox->setText( tr("Show Selected Object Only"));
2397 cbradney 310
        undoButton->setText( tr("&Undo"));
311
        redoButton->setText( tr("&Redo"));
12208 cbradney 312
 
313
        objectBox->setToolTip( "<qt>" + tr( "Show the action history for the selected item only. This changes the effect of the undo/redo buttons to act on the object or document." ) + "</qt>" );
314
        undoButton->setToolTip( "<qt>" + tr( "Undo the last action for either the current object or the document" ) + "</qt>");
315
        redoButton->setToolTip( "<qt>" + tr( "Redo the last action for either the current object or the document" ) + "</qt>");
2198 cbradney 316
}
317
 
1111 tsoots 318
void UndoPalette::insertUndoItem(UndoObject* target, UndoState* state)
319
{
10987 subik 320
//      qDebug() << "UndoPalette::insertUndoItem start";
1457 tsoots 321
        clearRedo();
10483 subik 322
        undoList->addItem(new UndoItem(target->getUName(), state->getName(),
1250 tsoots 323
                         state->getDescription(), target->getUPixmap(),
5950 tsoots 324
                         state->getPixmap(), true));
10483 subik 325
        currentSelection = undoList->count() - 1;
1111 tsoots 326
        updateList();
10987 subik 327
//      qDebug() << "UndoPalette::insertUndoItem end";
1111 tsoots 328
}
329
 
330
void UndoPalette::insertRedoItem(UndoObject* target, UndoState* state)
331
{
10987 subik 332
//      qDebug() << "UndoPalette::insertRedoItem start";
1190 tsoots 333
        if (undoList->count() == 1)
1443 tsoots 334
        {
10987 subik 335
//              qDebug() << "UndoPalette::insertRedoItem undoList->count == 1";
10483 subik 336
//              undoList->setSelected(0, true);
337
                undoList->setCurrentItem(undoList->item(0));
1443 tsoots 338
                currentSelection = 0;
339
        }
10483 subik 340
        undoList->addItem(new UndoItem(target->getUName(), state->getName(),
1250 tsoots 341
                         state->getDescription(), target->getUPixmap(),
5950 tsoots 342
                         state->getPixmap(), false));
1111 tsoots 343
        updateList();
10987 subik 344
//      qDebug() << "UndoPalette::insertRedoItem end";
1111 tsoots 345
}
346
 
347
void UndoPalette::updateUndo(int steps)
348
{
10987 subik 349
//      qDebug() << "UndoPalette::updateUndo start";
10483 subik 350
        if (undoList->row(undoList->currentItem()) == currentSelection)
1111 tsoots 351
        {
352
                currentSelection -= steps;
353
                updateList();
354
        }
10987 subik 355
//      qDebug() << "UndoPalette::updateUndo end";
1111 tsoots 356
}
357
 
358
void UndoPalette::updateRedo(int steps)
359
{
10987 subik 360
//      qDebug() << "UndoPalette::updateRedo start";
10483 subik 361
        if (undoList->row(undoList->currentItem()) == currentSelection)
1111 tsoots 362
        {
363
                currentSelection += steps;
364
                updateList();
365
        }
10987 subik 366
//      qDebug() << "UndoPalette::updateRedo end";
1111 tsoots 367
}
368
 
369
void UndoPalette::popBack()
370
{
10987 subik 371
//      qDebug() << "UndoPalette::popBack start";
1197 tsoots 372
        if (undoList->count() > 1)
373
        {
10483 subik 374
//              undoList->removeItem(0);
375
                delete undoList->takeItem(0);
376
                currentSelection = undoList->count() - 1;
1197 tsoots 377
        }
10987 subik 378
//      qDebug() << "UndoPalette::popBack end";
1111 tsoots 379
}
380
 
381
void UndoPalette::updateList()
382
{
10987 subik 383
//      qDebug() << "UndoPalette::updateList start";
10483 subik 384
//      undoList->setCurrentItem(currentSelection);
385
        undoList->setCurrentRow(currentSelection);
386
//      undoList->setSelected(currentSelection, true);
387
        redoButton->setEnabled(currentSelection < undoList->count() - 1);
1111 tsoots 388
        undoButton->setEnabled(currentSelection > 0);
10483 subik 389
//      if (!undoList->item(currentSelection)->isVisible()) //itemVisible(currentSelection))
390
//              undoList->setBottomItem(currentSelection);
391
        undoList->scrollToItem(undoList->item(currentSelection));
392
        for (int i = 0; i < undoList->count(); ++i)
5950 tsoots 393
        {
394
                UndoItem *item = dynamic_cast<UndoItem*>(undoList->item(i));
395
                if (!item)
396
                        continue;
397
 
398
                item->setUndoAction(currentSelection >= i);
399
        }
10987 subik 400
//      qDebug() << "UndoPalette::updateList end";
1111 tsoots 401
}
402
 
4985 cbradney 403
void UndoPalette::updateUndoActions()
404
{
405
        //ScMW->scrActions["editUndoAction"]->setEnabled(currentSelection > 0);
406
        //ScMW->scrActions["editRedoAction"]->setEnabled(currentSelection < undoList->numRows() - 1);
407
}
408
 
1457 tsoots 409
void UndoPalette::clearRedo()
1111 tsoots 410
{
10987 subik 411
//      qDebug() << "UndoPalette::clearRedo start";
10483 subik 412
        for (int i = (undoList->count() - 1); i > currentSelection; --i)
413
//              undoList->removeItem(i);
414
                delete undoList->takeItem(i);
10987 subik 415
//      qDebug() << "UndoPalette::clearRedo end";
1111 tsoots 416
}
417
 
418
void UndoPalette::undoClicked()
419
{
10987 subik 420
//      qDebug() << "UndoPalette::undoClicked emitted";
1111 tsoots 421
        emit undo(1);
422
}
423
 
424
void UndoPalette::redoClicked()
425
{
10987 subik 426
//      qDebug() << "UndoPalette::redoClicked emitted";
1111 tsoots 427
        emit redo(1);
428
}
429
 
430
void UndoPalette::undoListClicked(int i)
431
{
10987 subik 432
//      qDebug() << "UndoPalette::undoListClicked start";
1190 tsoots 433
        if (i == currentSelection || (i == 0 && undoList->count() == 1))
1111 tsoots 434
                return;
435
        if (i > currentSelection)
436
                emit redo(i - currentSelection);
437
        else if (i < currentSelection)
438
                emit undo(currentSelection - i);
439
        currentSelection = i;
440
        updateList();
10987 subik 441
//      qDebug() << "UndoPalette::undoListClicked end";
1111 tsoots 442
}
443
 
1443 tsoots 444
void UndoPalette::objectCheckBoxClicked(bool on)
445
{
10987 subik 446
//      qDebug() << "UndoPalette::objectCheckBoxClicked start";
1443 tsoots 447
        emit objectMode(on);
10987 subik 448
//      qDebug() << "UndoPalette::objectCheckBoxClicked end";
1443 tsoots 449
}
450
 
10483 subik 451
void UndoPalette::showToolTip(QListWidgetItem *i)
1200 tsoots 452
{
10987 subik 453
//      qDebug() << "UndoPalette::showToolTip start";
1200 tsoots 454
        UndoItem *item = dynamic_cast<UndoItem*>(i);
455
        if (item)
456
        {
457
                QString tip = item->getDescription();
11584 herm 458
                if (!tip.isNull()) /*TODO: Doesn't make sense! */
10397 cbradney 459
                  undoList->setToolTip(tip);
1200 tsoots 460
        }
461
        else
462
                removeToolTip();
10987 subik 463
//      qDebug() << "UndoPalette::showToolTip end";
1200 tsoots 464
}
465
 
466
void UndoPalette::removeToolTip()
467
{
10987 subik 468
//      qDebug() << "UndoPalette::removeToolTip start";
10397 cbradney 469
        undoList->setToolTip("");
10987 subik 470
//      qDebug() << "UndoPalette::removeToolTip end";
1200 tsoots 471
}
472
 
1111 tsoots 473
UndoPalette::~UndoPalette()
474
{
11292 subik 475
 
1111 tsoots 476
}
1142 tsoots 477
 
478
/*** UndoPalette::UndoItem ****************************************************/
479
 
10483 subik 480
UndoPalette::UndoItem::UndoItem() : QListWidgetItem()
1142 tsoots 481
{
482
        target = "";
483
        action = "";
1200 tsoots 484
        description = "";
1250 tsoots 485
        targetpixmap = NULL;
486
        actionpixmap = NULL;
5950 tsoots 487
        isUndoAction_ = true;
1142 tsoots 488
}
489
 
10483 subik 490
UndoPalette::UndoItem::UndoItem(const UndoItem &another) : QListWidgetItem()
1142 tsoots 491
{
492
        target = another.target;
493
        action = another.action;
1200 tsoots 494
        description = another.description;
1250 tsoots 495
        targetpixmap = another.targetpixmap;
496
        actionpixmap = another.actionpixmap;
5950 tsoots 497
        isUndoAction_ = another.isUndoAction_;
1142 tsoots 498
}
499
 
1250 tsoots 500
UndoPalette::UndoItem::UndoItem(const QString &targetName,
501
                                const QString &actionName,
502
                                const QString &actionDescription,
503
                                QPixmap *targetPixmap,
5950 tsoots 504
                                QPixmap *actionPixmap,
10548 subik 505
                                bool isUndoAction,
506
                                QListWidget * parent
507
                                                           )
508
        : QListWidgetItem(parent),
10483 subik 509
        targetpixmap(targetPixmap),
510
        actionpixmap(actionPixmap),
511
        target(targetName),
512
        action(actionName),
513
        description(actionDescription),
514
        isUndoAction_(isUndoAction)
1142 tsoots 515
{
11584 herm 516
        /*TODO: 16x16 is hardcoded, because images automatically scaled by QIcon are no longer recognizable
517
        would be better to have the icons designed for 16x16*/
518
        if (!targetPixmap) {
519
                if (actionPixmap) {
520
                        setIcon(actionPixmap->scaled(16,16));
521
                }
522
        } else {
523
                QPixmap pixmap = targetPixmap->scaled(16,16);
524
                if (actionPixmap) {
525
                        QPainter p;
526
                        p.begin(&pixmap);
527
                        p.drawPixmap(0,0, actionPixmap->scaled(16,16));
528
                        p.end();
529
                }
530
                setIcon(pixmap);
531
        }
16065 craig 532
        setText(tr("%1 - %2\n%3").arg(targetName).arg(actionName).arg(actionDescription));
1142 tsoots 533
}
534
 
11584 herm 535
//void UndoPalette::UndoItem::paint(QPainter *painter)
536
//{
10548 subik 537
//      if (targetpixmap)
538
//              painter->drawPixmap(5, 5, *targetpixmap);
539
//      if (actionpixmap)
540
//              painter->drawPixmap(5, 5, *actionpixmap);
541
//      QPen  p = QPen(painter->pen());
542
//      QFont f = QFont(painter->font());
543
//      painter->setFont(f);
544
//      if (isUndoAction_)
545
//      {
546
//              p.setColor(QColor("black"));
547
//              f.setItalic(false);
548
//      }
549
//      else
550
//      {
551
//              p.setColor(QColor("darkGray"));
552
//              f.setItalic(true);
553
//      }
554
//      painter->setPen(p);
555
//      painter->setFont(f);
556
//      painter->drawText(32, QFontMetrics(f).height(), target);
557
//      painter->drawText(32, (2 * QFontMetrics(painter->font()).height()), action);
11584 herm 558
//}
1142 tsoots 559
 
11584 herm 560
/*
10483 subik 561
int UndoPalette::UndoItem::height(const QListWidget *lb) const
1142 tsoots 562
{
1167 tsoots 563
        if (lb)
1204 tsoots 564
        {
5952 tsoots 565
                int fontHeight = 2 * QFontMetrics(lb->font()).lineSpacing() + 2;
1250 tsoots 566
                if (actionpixmap)
1254 tsoots 567
                        return fontHeight > (10 + actionpixmap->height()) ?
568
                   fontHeight : (10 + actionpixmap->height());
1250 tsoots 569
                else if (targetpixmap)
1254 tsoots 570
                        return fontHeight > (10 + targetpixmap->height()) ?
571
                   fontHeight : (10 + targetpixmap->height());
1204 tsoots 572
                else
573
                        return fontHeight;
574
        }
1167 tsoots 575
        else
576
                return 0;
1142 tsoots 577
}
578
 
10483 subik 579
int UndoPalette::UndoItem::width(const QListWidget *lb) const
1142 tsoots 580
{
1167 tsoots 581
        if (lb)
582
                return target.length() > action.length() ?
1250 tsoots 583
               39 + QFontMetrics(lb->font()).width(target) :
584
               39 + QFontMetrics(lb->font()).width(action);
1167 tsoots 585
        else
586
                return 0;
1142 tsoots 587
}
11584 herm 588
*/
1142 tsoots 589
 
1200 tsoots 590
QString UndoPalette::UndoItem::getDescription()
591
{
592
  return description;
593
}
594
 
5950 tsoots 595
bool UndoPalette::UndoItem::isUndoAction()
596
{
597
        return isUndoAction_;
598
}
599
 
600
void UndoPalette::UndoItem::setUndoAction(bool isUndo)
601
{
602
        isUndoAction_ = isUndo;
11584 herm 603
        QFont f = font();
604
        f.setItalic(!isUndoAction_);
605
        setFont(f);
5950 tsoots 606
}
607
 
1142 tsoots 608
UndoPalette::UndoItem::~UndoItem()
609
{
1443 tsoots 610
 
1142 tsoots 611
}