Scribus
Open source desktop publishing at your fingertips
undogui.h
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 */
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  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25  ***************************************************************************/
26 
27 #ifndef UNDOGUI_H
28 #define UNDOGUI_H
29 
30 #include <QListWidgetItem>
31 #include <QPushButton>
32 
33 #include "scribusapi.h"
34 #include "undoobject.h"
35 #include "undostate.h"
36 #include "ui/scdockpalette.h"
37 
38 class QEvent;
39 class QMenu;
40 class QListWidget;
41 class QCheckBox;
42 
43 
59 class SCRIBUS_API UndoGui : public ScDockPalette
60 {
61  Q_OBJECT
62 
63 public:
70  UndoGui(QWidget* parent = 0, const char* name = "UndoGui", Qt::WindowFlags f = 0);
71 
73  virtual ~UndoGui() {};
74 
76  virtual void clear() = 0;
77 
79  virtual void languageChange();
80 
81 public slots:
91  virtual void insertUndoItem(UndoObject* target, UndoState* state) = 0;
92 
98  virtual void insertRedoItem(UndoObject* target, UndoState* state) = 0;
99 
108  virtual void updateUndo(int steps) = 0;
109 
118  virtual void updateRedo(int steps) = 0;
119 
123  virtual void updateUndoActions() = 0;
124 
126  virtual void clearRedo() = 0;
127 
129  virtual void popBack() = 0;
130 /* signals: do not implement these but emit when action happens
131  virtual void undo(int steps) = 0;
132  virtual void redo(int steps) = 0;
133 */
134 };
135 
136 /*** UndoGui implementations **************************************************/
137 /*** UndoWidget ***************************************************************/
138 
148 class SCRIBUS_API UndoWidget : public UndoGui
149 {
150  Q_OBJECT
151 
152 private:
154  static const uint MENU_HEIGHT = 5;
155  std::vector<QString> undoItems;
156  std::vector<QString> redoItems;
157  /* BnF buttons
158  QToolButton* undoButton;
159  QToolButton* redoButton;
160  */
161  QMenu* undoMenu;
162  QMenu* redoMenu;
163  void updateUndoMenu();
164  void updateRedoMenu();
165 public:
167  UndoWidget(QWidget* parent = 0, const char* name = 0);
168 
170  virtual ~UndoWidget();
171 
173  void clear();
177  virtual void updateUndoActions();
178 
179 private slots:
180  void undoClicked();
181  void redoClicked();
182  void undoMenuClicked(QAction *id);
183  void redoMenuClicked(QAction *id);
184 public slots:
194  void insertUndoItem(UndoObject* target, UndoState* state);
195 
201  void insertRedoItem(UndoObject* target, UndoState* state);
202 
211  void updateUndo(int steps);
212 
221  void updateRedo(int steps);
222 
224  void clearRedo();
225 
227  void popBack();
228 signals:
235  void undo(int steps);
236 
243  void redo(int steps);
244 };
245 
246 /*** UndoPalette **************************************************************/
247 
259 class SCRIBUS_API UndoPalette : public UndoGui
260 {
261  Q_OBJECT
262 
263 private:
264  QWidget* container;
265  int currentSelection;
266  int redoItems;
267  QListWidget* undoList;
268  QCheckBox* objectBox;
269  QPushButton* undoButton;
270  QPushButton* redoButton;
271  QKeySequence initialUndoKS;
272  QKeySequence initialRedoKS;
273  void updateList();
274  void removeRedoItems();
275 
276 /*** UndoPalette::UndoItem ****************************************************/
277 
279  class UndoItem : public QListWidgetItem
280  {
281  private:
283  QPixmap *targetpixmap;
285  QPixmap *actionpixmap;
287  QString target;
289  QString action;
291  QString description;
293  bool isUndoAction_;
294  public:
296  UndoItem();
301  UndoItem(const UndoItem &another);
314  UndoItem(const QString &targetName,
315  const QString &actionName,
316  const QString &actionDescription,
317  QPixmap *targetPixmap,
318  QPixmap *actionPixmap,
319  bool isUndoAction,
320  QListWidget * parent = 0);
321  ~UndoItem();
322  /*void paint(QPainter *painter);
323  int height(const QListWidget*) const;
324  int width(const QListWidget*) const;*/
325  QString getDescription();
326  bool isUndoAction();
327  void setUndoAction(bool isUndo);
328  };
329 
330 /******************************************************************************/
331 
332 private slots:
333  void undoClicked();
334  void redoClicked();
335  void undoListClicked(int i);
336  void showToolTip(QListWidgetItem *i);
337  void removeToolTip();
338  void objectCheckBoxClicked(bool on);
339 
340 public:
347  UndoPalette(QWidget* parent = 0, const char* name = 0);
348 
350  ~UndoPalette();
351 
352  virtual void changeEvent(QEvent *e);
353 
355  void clear();
359  virtual void updateUndoActions();
360 
361 public slots:
363  void languageChange();
364 
374  void insertUndoItem(UndoObject* target, UndoState* state);
375 
381  void insertRedoItem(UndoObject* target, UndoState* state);
382 
391  void updateUndo(int steps);
392 
401  void updateRedo(int steps);
402 
404  void clearRedo();
405 
407  void popBack();
408 
410  void updateFromPrefs();
411 
412 signals:
413 
419  void objectMode(bool isEnabled);
426  void undo(int steps);
427 
434  void redo(int steps);
435 
436 };
437 
438 #endif // UNDOGUI_H
virtual ~UndoGui()
Destroys the widget.
Definition: undogui.h:73
virtual void clear()=0
Empties the undo stack representation.
UndoGui subclass which creates an undo history window.
Definition: undogui.h:259
Definition: scdockpalette.h:38
UndoState describes an undoable state (action).
Definition: undostate.h:59
virtual void updateUndoActions()=0
Update the scrActions.
virtual void insertUndoItem(UndoObject *target, UndoState *state)=0
Insert a new undo item.
UndoGui is a virtual superclass for undo/redo widgets.
Definition: undogui.h:59
virtual void insertRedoItem(UndoObject *target, UndoState *state)=0
Insert a new redo item.
Tool bar buttons with pop up menus for undo and redo.
Definition: undogui.h:148
virtual void updateUndo(int steps)=0
Update undo stack representation with number of steps.
Superclass for all objects that are wanted to have undoable actions.
Definition: undoobject.h:59
virtual void languageChange()
Sets GUI strings on language change.
Definition: undogui.cpp:46
virtual void updateRedo(int steps)=0
Update redo stack representation with number of steps.
virtual void clearRedo()=0
Clear the redo action items.
virtual void popBack()=0
Remove the last (oldest) item from the undo stack representation.