Subversion Repositories Scribus

Rev

Rev 10987 | Rev 11584 | 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"
1288 cbradney 35
#include "menumanager.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"));
2397 cbradney 309
        objectBox->setText( tr("Show selected object only"));
310
        undoButton->setText( tr("&Undo"));
311
        redoButton->setText( tr("&Redo"));
2198 cbradney 312
}
313
 
1111 tsoots 314
void UndoPalette::insertUndoItem(UndoObject* target, UndoState* state)
315
{
10987 subik 316
//      qDebug() << "UndoPalette::insertUndoItem start";
1457 tsoots 317
        clearRedo();
10483 subik 318
        undoList->addItem(new UndoItem(target->getUName(), state->getName(),
1250 tsoots 319
                         state->getDescription(), target->getUPixmap(),
5950 tsoots 320
                         state->getPixmap(), true));
10483 subik 321
        currentSelection = undoList->count() - 1;
1111 tsoots 322
        updateList();
10987 subik 323
//      qDebug() << "UndoPalette::insertUndoItem end";
1111 tsoots 324
}
325
 
326
void UndoPalette::insertRedoItem(UndoObject* target, UndoState* state)
327
{
10987 subik 328
//      qDebug() << "UndoPalette::insertRedoItem start";
1190 tsoots 329
        if (undoList->count() == 1)
1443 tsoots 330
        {
10987 subik 331
//              qDebug() << "UndoPalette::insertRedoItem undoList->count == 1";
10483 subik 332
//              undoList->setSelected(0, true);
333
                undoList->setCurrentItem(undoList->item(0));
1443 tsoots 334
                currentSelection = 0;
335
        }
10483 subik 336
        undoList->addItem(new UndoItem(target->getUName(), state->getName(),
1250 tsoots 337
                         state->getDescription(), target->getUPixmap(),
5950 tsoots 338
                         state->getPixmap(), false));
1111 tsoots 339
        updateList();
10987 subik 340
//      qDebug() << "UndoPalette::insertRedoItem end";
1111 tsoots 341
}
342
 
343
void UndoPalette::updateUndo(int steps)
344
{
10987 subik 345
//      qDebug() << "UndoPalette::updateUndo start";
10483 subik 346
        if (undoList->row(undoList->currentItem()) == currentSelection)
1111 tsoots 347
        {
348
                currentSelection -= steps;
349
                updateList();
350
        }
10987 subik 351
//      qDebug() << "UndoPalette::updateUndo end";
1111 tsoots 352
}
353
 
354
void UndoPalette::updateRedo(int steps)
355
{
10987 subik 356
//      qDebug() << "UndoPalette::updateRedo start";
10483 subik 357
        if (undoList->row(undoList->currentItem()) == currentSelection)
1111 tsoots 358
        {
359
                currentSelection += steps;
360
                updateList();
361
        }
10987 subik 362
//      qDebug() << "UndoPalette::updateRedo end";
1111 tsoots 363
}
364
 
365
void UndoPalette::popBack()
366
{
10987 subik 367
//      qDebug() << "UndoPalette::popBack start";
1197 tsoots 368
        if (undoList->count() > 1)
369
        {
10483 subik 370
//              undoList->removeItem(0);
371
                delete undoList->takeItem(0);
372
                currentSelection = undoList->count() - 1;
1197 tsoots 373
        }
10987 subik 374
//      qDebug() << "UndoPalette::popBack end";
1111 tsoots 375
}
376
 
377
void UndoPalette::updateList()
378
{
10987 subik 379
//      qDebug() << "UndoPalette::updateList start";
10483 subik 380
//      undoList->setCurrentItem(currentSelection);
381
        undoList->setCurrentRow(currentSelection);
382
//      undoList->setSelected(currentSelection, true);
383
        redoButton->setEnabled(currentSelection < undoList->count() - 1);
1111 tsoots 384
        undoButton->setEnabled(currentSelection > 0);
10483 subik 385
//      if (!undoList->item(currentSelection)->isVisible()) //itemVisible(currentSelection))
386
//              undoList->setBottomItem(currentSelection);
387
        undoList->scrollToItem(undoList->item(currentSelection));
388
        for (int i = 0; i < undoList->count(); ++i)
5950 tsoots 389
        {
390
                UndoItem *item = dynamic_cast<UndoItem*>(undoList->item(i));
391
                if (!item)
392
                        continue;
393
 
394
                item->setUndoAction(currentSelection >= i);
395
        }
10987 subik 396
//      qDebug() << "UndoPalette::updateList end";
1111 tsoots 397
}
398
 
4985 cbradney 399
void UndoPalette::updateUndoActions()
400
{
401
        //ScMW->scrActions["editUndoAction"]->setEnabled(currentSelection > 0);
402
        //ScMW->scrActions["editRedoAction"]->setEnabled(currentSelection < undoList->numRows() - 1);
403
}
404
 
1457 tsoots 405
void UndoPalette::clearRedo()
1111 tsoots 406
{
10987 subik 407
//      qDebug() << "UndoPalette::clearRedo start";
10483 subik 408
        for (int i = (undoList->count() - 1); i > currentSelection; --i)
409
//              undoList->removeItem(i);
410
                delete undoList->takeItem(i);
10987 subik 411
//      qDebug() << "UndoPalette::clearRedo end";
1111 tsoots 412
}
413
 
414
void UndoPalette::undoClicked()
415
{
10987 subik 416
//      qDebug() << "UndoPalette::undoClicked emitted";
1111 tsoots 417
        emit undo(1);
418
}
419
 
420
void UndoPalette::redoClicked()
421
{
10987 subik 422
//      qDebug() << "UndoPalette::redoClicked emitted";
1111 tsoots 423
        emit redo(1);
424
}
425
 
426
void UndoPalette::undoListClicked(int i)
427
{
10987 subik 428
//      qDebug() << "UndoPalette::undoListClicked start";
1190 tsoots 429
        if (i == currentSelection || (i == 0 && undoList->count() == 1))
1111 tsoots 430
                return;
431
        if (i > currentSelection)
432
                emit redo(i - currentSelection);
433
        else if (i < currentSelection)
434
                emit undo(currentSelection - i);
435
        currentSelection = i;
436
        updateList();
10987 subik 437
//      qDebug() << "UndoPalette::undoListClicked end";
1111 tsoots 438
}
439
 
1443 tsoots 440
void UndoPalette::objectCheckBoxClicked(bool on)
441
{
10987 subik 442
//      qDebug() << "UndoPalette::objectCheckBoxClicked start";
1443 tsoots 443
        emit objectMode(on);
10987 subik 444
//      qDebug() << "UndoPalette::objectCheckBoxClicked end";
1443 tsoots 445
}
446
 
10483 subik 447
void UndoPalette::showToolTip(QListWidgetItem *i)
1200 tsoots 448
{
10987 subik 449
//      qDebug() << "UndoPalette::showToolTip start";
1200 tsoots 450
        UndoItem *item = dynamic_cast<UndoItem*>(i);
451
        if (item)
452
        {
453
                QString tip = item->getDescription();
8627 subik 454
                if (tip.isNull())
10397 cbradney 455
                  undoList->setToolTip(tip);
1200 tsoots 456
        }
457
        else
458
                removeToolTip();
10987 subik 459
//      qDebug() << "UndoPalette::showToolTip end";
1200 tsoots 460
}
461
 
462
void UndoPalette::removeToolTip()
463
{
10987 subik 464
//      qDebug() << "UndoPalette::removeToolTip start";
10397 cbradney 465
        undoList->setToolTip("");
10987 subik 466
//      qDebug() << "UndoPalette::removeToolTip end";
1200 tsoots 467
}
468
 
1111 tsoots 469
UndoPalette::~UndoPalette()
470
{
11292 subik 471
 
1111 tsoots 472
}
1142 tsoots 473
 
474
/*** UndoPalette::UndoItem ****************************************************/
475
 
10483 subik 476
UndoPalette::UndoItem::UndoItem() : QListWidgetItem()
1142 tsoots 477
{
478
        target = "";
479
        action = "";
1200 tsoots 480
        description = "";
1250 tsoots 481
        targetpixmap = NULL;
482
        actionpixmap = NULL;
5950 tsoots 483
        isUndoAction_ = true;
1142 tsoots 484
}
485
 
10483 subik 486
UndoPalette::UndoItem::UndoItem(const UndoItem &another) : QListWidgetItem()
1142 tsoots 487
{
488
        target = another.target;
489
        action = another.action;
1200 tsoots 490
        description = another.description;
1250 tsoots 491
        targetpixmap = another.targetpixmap;
492
        actionpixmap = another.actionpixmap;
5950 tsoots 493
        isUndoAction_ = another.isUndoAction_;
1142 tsoots 494
}
495
 
1250 tsoots 496
UndoPalette::UndoItem::UndoItem(const QString &targetName,
497
                                const QString &actionName,
498
                                const QString &actionDescription,
499
                                QPixmap *targetPixmap,
5950 tsoots 500
                                QPixmap *actionPixmap,
10548 subik 501
                                bool isUndoAction,
502
                                QListWidget * parent
503
                                                           )
504
        : QListWidgetItem(parent),
10483 subik 505
        targetpixmap(targetPixmap),
506
        actionpixmap(actionPixmap),
507
        target(targetName),
508
        action(actionName),
509
        description(actionDescription),
510
        isUndoAction_(isUndoAction)
1142 tsoots 511
{
10987 subik 512
//      qDebug() << "UndoItem::contructor";
10548 subik 513
/*      QFont f;
514
        f.setItalic(!isUndoAction_);
515
        setFont(f);*/
516
        setText(QString("%1 - %2\n%3").arg(targetName).arg(actionName).arg(actionDescription));
1142 tsoots 517
}
518
 
519
void UndoPalette::UndoItem::paint(QPainter *painter)
520
{
10548 subik 521
//      if (targetpixmap)
522
//              painter->drawPixmap(5, 5, *targetpixmap);
523
//      if (actionpixmap)
524
//              painter->drawPixmap(5, 5, *actionpixmap);
525
//      QPen  p = QPen(painter->pen());
526
//      QFont f = QFont(painter->font());
527
//      painter->setFont(f);
528
//      if (isUndoAction_)
529
//      {
530
//              p.setColor(QColor("black"));
531
//              f.setItalic(false);
532
//      }
533
//      else
534
//      {
535
//              p.setColor(QColor("darkGray"));
536
//              f.setItalic(true);
537
//      }
538
//      painter->setPen(p);
539
//      painter->setFont(f);
540
//      painter->drawText(32, QFontMetrics(f).height(), target);
541
//      painter->drawText(32, (2 * QFontMetrics(painter->font()).height()), action);
1142 tsoots 542
}
543
 
10483 subik 544
int UndoPalette::UndoItem::height(const QListWidget *lb) const
1142 tsoots 545
{
1167 tsoots 546
        if (lb)
1204 tsoots 547
        {
5952 tsoots 548
                int fontHeight = 2 * QFontMetrics(lb->font()).lineSpacing() + 2;
1250 tsoots 549
                if (actionpixmap)
1254 tsoots 550
                        return fontHeight > (10 + actionpixmap->height()) ?
551
                   fontHeight : (10 + actionpixmap->height());
1250 tsoots 552
                else if (targetpixmap)
1254 tsoots 553
                        return fontHeight > (10 + targetpixmap->height()) ?
554
                   fontHeight : (10 + targetpixmap->height());
1204 tsoots 555
                else
556
                        return fontHeight;
557
        }
1167 tsoots 558
        else
559
                return 0;
1142 tsoots 560
}
561
 
10483 subik 562
int UndoPalette::UndoItem::width(const QListWidget *lb) const
1142 tsoots 563
{
1167 tsoots 564
        if (lb)
565
                return target.length() > action.length() ?
1250 tsoots 566
               39 + QFontMetrics(lb->font()).width(target) :
567
               39 + QFontMetrics(lb->font()).width(action);
1167 tsoots 568
        else
569
                return 0;
1142 tsoots 570
}
571
 
1200 tsoots 572
QString UndoPalette::UndoItem::getDescription()
573
{
574
  return description;
575
}
576
 
5950 tsoots 577
bool UndoPalette::UndoItem::isUndoAction()
578
{
579
        return isUndoAction_;
580
}
581
 
582
void UndoPalette::UndoItem::setUndoAction(bool isUndo)
583
{
584
        isUndoAction_ = isUndo;
585
}
586
 
1142 tsoots 587
UndoPalette::UndoItem::~UndoItem()
588
{
1443 tsoots 589
 
1142 tsoots 590
}