Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 1189 → Rev 1190

/branches/Version13x/Scribus/scribus/page.h
21,13 → 21,14
class QString;
#include "qvaluelist.h"
#include "qptrlist.h"
#include "qpixmap.h"
 
#include "undomanager.h"
#include "undoobject.h"
#include "undostate.h"
#include "scribusstructs.h"
#include "pageitem.h"
 
class UndoManager;
class UndoState;
 
/**
*@author Franz Schmid
*/
34,7 → 35,6
class Page : public UndoObject
{
private:
QPixmap undoIcon;
UndoManager* undoManager;
public:
Page(double x, double y, double b, double h);
/branches/Version13x/Scribus/scribus/undomanager.h
25,6 → 25,7
#include <utility>
#include <qobject.h>
#include <qpixmap.h>
#include <qstring.h>
#include "undostate.h"
#include "undoobject.h"
 
101,6 → 102,7
 
void connectGuis();
void disconnectGuis();
void initIcons();
 
public:
/**
209,6 → 211,30
*/
int getHistoryLength();
 
/***
* @name Action strings
* Strings describing undo actions
*/
/*@{*/
static const QString AddVGuide;
static const QString AddHGuide;
static const QString DelVGuide;
static const QString DelHGuide;
static const QString MoveVGuide;
static const QString MoveHGuide;
static const QString LockGuides;
static const QString UnlockGuides;
/*@}*/
/**
* @name Action icons
* Icons for undo actions
*/
/*@{*/
static QPixmap *IGuides;
static QPixmap *ILockGuides;
/*@}*/
 
protected:
/** @brief Creates a new UndoManager instance */
UndoManager();
279,7 → 305,8
* @brief Emitted when an undo action has been done.
*
* It is connected to attached guis to inform them to update the visual
* representation of the undo stack.
* representation of the undo stack. This signal will be also sent to the
* <code>UndoGui</code> where it came from.
* @param steps Number of steps to take
*/
void undoSignal(int steps);
305,6 → 332,9
* again after undo/redo.
*/
void undoRedoDone();
 
};
 
typedef UndoManager Um;
 
#endif
/branches/Version13x/Scribus/scribus/undogui.cpp
262,6 → 262,8
 
void UndoPalette::insertRedoItem(UndoObject* target, UndoState* state)
{
if (undoList->count() == 1)
undoList->setSelected(0, true);
undoList->insertItem(new UndoItem(target->getUName(), state->getName(), state->getPixmap()));
updateList();
}
318,7 → 320,7
 
void UndoPalette::undoListClicked(int i)
{
if (i == currentSelection)
if (i == currentSelection || (i == 0 && undoList->count() == 1))
return;
if (i > currentSelection)
emit redo(i - currentSelection);
368,11 → 370,6
f.setItalic(true);
painter->setFont(f);
painter->drawText(32, (2 * QFontMetrics(painter->font()).height()), action);
// if ( isSelected() )
// painter->eraseRect( r );
// painter->fillRect( 5, 5, width( listBox() ) - 10, height( listBox() ) - 10, Qt::red );
// if ( isCurrent() )
// listBox()->style().drawPrimitive( QStyle::PE_FocusRect, painter, r, listBox()->colorGroup() );
}
 
int UndoPalette::UndoItem::height(const QListBox *lb) const
/branches/Version13x/Scribus/scribus/page.cpp
17,6 → 17,8
 
#include "page.h"
#include "scribus.h"
#include "undomanager.h"
#include "undostate.h"
 
extern QPixmap loadIcon(QString nam);
extern ScribusApp *ScApp;
36,7 → 38,6
XGuides.clear();
YGuides.clear();
FromMaster.clear();
undoIcon = loadIcon("u_margins.png");
undoManager = UndoManager::instance();
}
 
57,7 → 58,7
qHeapSort(XGuides);
if (UndoManager::undoEnabled())
{
SimpleState* ss = new SimpleState(QObject::tr("Add vertical guide"), 0, &undoIcon);
SimpleState* ss = new SimpleState(Um::AddVGuide, 0, Um::IGuides);
ss->set("ADD_V", position);
undoManager->action(this, ss);
}
69,7 → 70,7
qHeapSort(YGuides);
if (UndoManager::undoEnabled())
{
SimpleState* ss = new SimpleState(QObject::tr("Add horizontal guide"), 0, &undoIcon);
SimpleState* ss = new SimpleState(Um::AddHGuide, 0, Um::IGuides);
ss->set("ADD_H", position);
undoManager->action(this, ss);
}
102,7 → 103,7
XGuides.remove(XGuides.find(position));
if (UndoManager::undoEnabled())
{
SimpleState* ss = new SimpleState(QObject::tr("Remove vertical guide"), 0, &undoIcon);
SimpleState* ss = new SimpleState(Um::DelVGuide, 0, Um::IGuides);
ss->set("REMOVE_V", position);
undoManager->action(this, ss);
}
119,7 → 120,7
YGuides.remove(YGuides.find(position));
if (UndoManager::undoEnabled())
{
SimpleState* ss = new SimpleState(QObject::tr("Remove horizontal guide"), 0, &undoIcon);
SimpleState* ss = new SimpleState(Um::DelHGuide, 0, Um::IGuides);
ss->set("REMOVE_H", position);
undoManager->action(this, ss);
}
141,7 → 142,7
undoManager->setUndoEnabled(tmpUndoEnabled);
if (UndoManager::undoEnabled())
{
SimpleState* ss = new SimpleState(QObject::tr("Move vertical guide"), 0, &undoIcon);
SimpleState* ss = new SimpleState(Um::MoveVGuide, 0, Um::IGuides);
ss->set("MOVE_V_FROM", from);
ss->set("MOVE_V_TO", to);
undoManager->action(this, ss);
158,7 → 159,7
undoManager->setUndoEnabled(tmpUndoEnabled);
if (UndoManager::undoEnabled())
{
SimpleState* ss = new SimpleState(QObject::tr("Move horizontal guide"), 0, &undoIcon);
SimpleState* ss = new SimpleState(Um::MoveHGuide, 0, Um::IGuides);
ss->set("MOVE_H_FROM", from);
ss->set("MOVE_H_TO", to);
undoManager->action(this, ss);
/branches/Version13x/Scribus/scribus/scribusdoc.cpp
254,7 → 254,6
ScratchBottom = prefsData->ScratchBottom;
arrowStyles = prefsData->arrowStyles;
undoManager = UndoManager::instance();
uGuideLockPixmap = loadIcon("u_margins_locked.png");
}
 
ScribusDoc::~ScribusDoc()
344,10 → 343,10
{
QString name;
if (isLocked)
name = QObject::tr("Lock guides");
name = Um::LockGuides;
else
name = QObject::tr("Unlock guides");
SimpleState *ss = new SimpleState(name, "", &uGuideLockPixmap);
name = Um::UnlockGuides;
SimpleState *ss = new SimpleState(name, "", Um::ILockGuides);
ss->set("GUIDE_LOCK", isLocked);
undoManager->action(this, ss);
}
374,6 → 373,8
QString uname = name;
if (name.find("/") > -1)
uname = name.right(name.length() - name.findRev("/") - 1);
if (uname.find(".sl") > -1)
uname = uname.left(uname.findRev(".sl"));
setUName(uname); // set the name for the undo object
}
 
/branches/Version13x/Scribus/scribus/undostate.h
48,7 → 48,7
/** @brief Detailed description of the state (action). */
QString actionDescription;
/** @brief Icon related to the state (action) */
QPixmap* actionPixmap;
QPixmap *actionPixmap;
public:
/**
* @brief Creates a new UndoState instance.
/branches/Version13x/Scribus/scribus/scribusdoc.h
34,7 → 34,6
#include <qtimer.h>
 
#include "scribusstructs.h"
#include "undomanager.h"
#include "undoobject.h"
#include "hyphenator.h"
#ifdef HAVE_CMS
44,6 → 43,8
#include <ft2build.h>
#include FT_FREETYPE_H
class Page;
class UndoManager;
class UndoState;
 
 
/**
71,7 → 72,7
* @author Riku Leino
*/
void lockGuides(bool isLocked);
/*
/**
* @brief Method used when an undo/redo is requested.
* @param state State describing the action that is wanted to be undone/redone
* @param isUndo If true undo is wanted else if false redo.
88,7 → 89,6
protected:
bool modified;
UndoManager *undoManager;
QPixmap uGuideLockPixmap;
 
public: // Public attributes
bool SnapGuides;
/branches/Version13x/Scribus/scribus/scribus.cpp
4172,6 → 4172,7
doc->setUnModified();
ActWin->setCaption(fn);
doc->setName(fn);
UndoManager::instance()->rename(fn);
fileMenu->setItemEnabled(fid4, 0);
fileMenu->setItemEnabled(fid52, 0);
DatSav->setEnabled(false);
/branches/Version13x/Scribus/scribus/undomanager.cpp
21,8 → 21,11
#include "undomanager.h"
#include "undomanager.moc"
#include "undogui.h"
#include "config.h"
#include <qvaluelist.h>
 
extern QPixmap loadIcon(QString nam);
 
UndoManager* UndoManager::_instance = 0;
bool UndoManager::_undoEnabled = true;
 
52,6 → 55,8
{
currentUndoObjectId = -1;
historyLength = 20;
if (!UndoManager::IGuides)
initIcons();
}
 
void UndoManager::registerGui(UndoGui* gui)
138,6 → 143,8
 
void UndoManager::rename(const QString& newName)
{
if (currentDoc == newName)
return;
StackPair tmp = stacks[currentDoc];
stacks.erase(currentDoc);
stacks[newName] = tmp;
158,6 → 165,7
{
for (uint i = 0; i < undoGuis.size(); ++i)
undoGuis[i]->clear();
currentDoc = "__no_name__";
}
}
}
200,41 → 208,51
 
void UndoManager::doUndo(int steps)
{
if (steps > 0 && _undoEnabled)
if (steps > 0 && _undoEnabled && stacks.size() > 0)
{
bool tmpUndoEnabled = _undoEnabled;
setUndoEnabled(false);
UndoState* tmpUndoState = NULL;
for (int i = 0; i < steps; ++i)
{
ActionPair aPair = *stacks[currentDoc].first;
UndoObject* tmpUndoObject = aPair.first;
UndoState* tmpUndoState = aPair.second;
tmpUndoObject->restore(tmpUndoState, true);
tmpUndoState = aPair.second;
if (tmpUndoState)
tmpUndoObject->restore(tmpUndoState, true);
++stacks[currentDoc].first;
}
setUndoEnabled(tmpUndoEnabled);
emit undoSignal(steps);
emit undoRedoDone();
if (tmpUndoState)
{
setUndoEnabled(tmpUndoEnabled);
emit undoSignal(steps);
emit undoRedoDone();
}
}
}
 
void UndoManager::doRedo(int steps)
{
if (steps > 0 && _undoEnabled)
if (steps > 0 && _undoEnabled && stacks.size() > 0)
{
bool tmpUndoEnabled = _undoEnabled;
setUndoEnabled(false);
UndoState* tmpUndoState = NULL;
for (int i = 0; i < steps; ++i)
{
--stacks[currentDoc].first;
ActionPair aPair = *stacks[currentDoc].first;
UndoObject* tmpUndoObject = aPair.first;
UndoState* tmpUndoState = aPair.second;
tmpUndoObject->restore(tmpUndoState, false);
tmpUndoState = aPair.second;
if (tmpUndoState)
tmpUndoObject->restore(tmpUndoState, false);
}
setUndoEnabled(tmpUndoEnabled);
emit redoSignal(steps);
emit undoRedoDone();
if (tmpUndoState)
{
setUndoEnabled(tmpUndoEnabled);
emit redoSignal(steps);
emit undoRedoDone();
}
}
}
 
283,3 → 301,22
}
}
}
 
void UndoManager::initIcons()
{
QString iconDir = ICONDIR;
UndoManager::IGuides = new QPixmap(iconDir + "u_margins.png");
UndoManager::ILockGuides = new QPixmap(iconDir + "u_margins_locked.png");
}
 
const QString UndoManager::AddVGuide = tr("Add vertical guide");
const QString UndoManager::AddHGuide = tr("Add horizontal guide");
const QString UndoManager::DelVGuide = tr("Remove vertical guide");
const QString UndoManager::DelHGuide = tr("Remove horizontal guide");
const QString UndoManager::MoveVGuide = tr("Move vertical guide");
const QString UndoManager::MoveHGuide = tr("Move horizontal guide");
const QString UndoManager::LockGuides = tr("Lock guides");
const QString UndoManager::UnlockGuides = tr("Unlock guides");
 
QPixmap *UndoManager::IGuides = NULL;
QPixmap *UndoManager::ILockGuides = NULL;