Back to index

scribus-ng  1.3.4.dfsg+svn20071115
stylemanager.h
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 
00008 #ifndef STYLEMANAGER_H
00009 #define STYLEMANAGER_H
00010 
00011 #include "scribusapi.h"
00012 #include "scraction.h"
00013 #include "stylemanagerbase.h"
00014 #include "scribusstructs.h"
00015 #include <qlistview.h>
00016 #include <qmap.h>
00017 #include <qguardedptr.h>
00018 
00019 class StyleItem;
00020 class ScribusDoc;
00021 class QHideEvent;
00022 class QGridLayout;
00023 class QTabWidget;
00024 class QVBoxLayout;
00025 class QHBoxLayout;
00026 class QButtonGroup;
00027 class QRadioButton;
00028 class QLabel;
00029 class QPushButton;
00030 class QSize;
00031 class ShortcutWidget;
00032 class QPopupMenu;
00033 class PrefsContext;
00034 class StyleView;
00035 
00036 class SCRIBUS_API StyleManager : public SMBase {
00037        Q_OBJECT
00038 public:
00039        StyleManager(QWidget *parent = 0, const char *name = "StyleManager");
00040        ~StyleManager();
00041 
00042        void addStyle(StyleItem *item);
00043        void updateColorList();
00044 
00045        QMap<QString,Keys> keyMap();
00046 
00047        void show();
00048 
00049 public slots:
00050        void setDoc(ScribusDoc *doc);
00051        void languageChange();
00052        void unitChange();
00053 
00054 signals:
00055        void closed();
00056 
00057 protected:
00058        void hideEvent(QHideEvent *e);
00059        void closeEvent(QCloseEvent *e);
00060        void showEvent(QShowEvent *e);
00061 
00062 private:
00063        QPtrList<StyleItem> items_;
00064        StyleItem          *item_;
00065        QGridLayout        *layout_;
00066        QTabWidget         *widget_;
00067        ShortcutWidget     *shortcutWidget_;
00068        QString             currentType_;
00069        QPopupMenu         *newPopup_;
00070        QPopupMenu         *rightClickPopup_;
00071        StyleView          *styleView;
00072        QHBoxLayout        *svLayout;
00073 
00074        int                 rcpNewId_;
00075        int                 rcpDeleteId_;
00076        int                 rcpEditId_;
00077        int                 rcpCloneId_;
00078        int                 rcpToScrapId_;
00079 
00080        bool                isEditMode_;
00081        bool                isStoryEditMode_;
00082        QPoint              editPosition_;
00083        int                 height_;
00084        int                 width_;
00085        int                 widthEm_;
00086        int                 widthLeft_;
00087        int                 widthRight_;
00088        QString             rcStyle_;
00089        QString             rcType_;
00090        QString             exitEditModeOk_;
00091        QString             enterEditModeOk_;
00092        QString             doneText;
00093        QString             editText;
00094 
00095        ScribusDoc         *doc_;
00096        PrefsContext       *prefs_;
00097 
00098        QMap<QString, QGuardedPtr<ScrAction> > styleActions_;
00099 
00100        static const int     NAME_COL     = 0;
00101        static const int     SHORTCUT_COL = 1;
00102        static const QString SEPARATOR;
00103 
00104        void insertShortcutPage(QTabWidget *twidget);
00105 
00106        bool nameIsUnique(const QString &name);
00107 
00108        // will be used to map plural style name to it's singular
00109        QMap<QString, QString> styleClassesPS_;
00110        QMap<QString, QString> styleClassesSP_;
00111 
00112        // QPair.first will be the type name (null if nothing is selected or
00113        // if there are styles from more than one type in the selection)
00114        // QPair.second will be the selected styles
00115        QPair<QString, QStringList> namesFromSelection();
00116        void loadType(const QString &name);
00117        void addNewType(StyleItem *item, bool loadFromDoc = true);
00118        void createNewStyle(const QString &typeName, const QString &fromParent = QString::null);
00119        void reloadStyleView(bool loadFromDoc = true); // are the styles loaded from doc or from tmp cache
00120        bool shortcutExists(const QString &keys);
00121        void updateActionName(const QString &oldName, const QString &newName);
00122        /* QPair.first = type name and QPair.second = style name */
00123        void setSelection(const QValueList<QPair<QString, QString> > &selected);
00124        void setOkButtonText();
00125 
00126 private slots:
00127        void slotOk();
00128        void slotApply();
00129        void slotDelete();
00130        void slotImport();
00131        void slotEdit();
00132        void slotClone();
00133        void slotNew();
00134        void slotNewPopup(int);
00135        void slotScrap();
00136        void slotRightClick(QListViewItem *item, const QPoint &point, int col);
00137        void slotDoubleClick(QListViewItem *item, const QPoint &point, int col);
00138 
00139        void slotNameChanged(const QString& name);
00140        void slotShortcutChanged(const QString& shortcut);
00141        void slotSetupWidget();
00142        void slotApplyStyle(QListViewItem *item);
00143        void slotDocSelectionChanged();
00144        void slotDocStylesChanged();
00145 
00146        void slotDirty();
00147        void slotClean();
00148 
00149        void slotApplyStyle(QString keyString); // keyString == styleClass$$$$styleName
00150 };
00151 
00152 class StyleView : public QListView
00153 {
00154        Q_OBJECT
00155 public:
00156        StyleView(QWidget *parent);
00157        ~StyleView();
00158 protected:
00159        void contentsMousePressEvent(QMouseEvent *e);
00160        void contentsMouseDoubleClickEvent(QMouseEvent *e);
00161 };
00162 
00163 class StyleViewItem : public QListViewItem
00164 {
00165 public:
00166        StyleViewItem(QListView *view, const QString &text);
00167        StyleViewItem(QListViewItem *parent, const QString &text, const QString &rootName);
00168        ~StyleViewItem();
00169 
00170        void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align);
00171 
00172        bool isRoot();
00173        QString parentName();
00174        QString rootName();
00175        void setDirty(bool isDirty);
00176        bool isDirty();
00177 
00178 private:
00179        bool isRoot_;
00180        bool isDirty_;
00181        QString parentName_;
00182        QString rootName_;
00183 };
00184 
00185 class ShortcutWidget : public QWidget
00186 {
00187        Q_OBJECT
00188 public:
00189        ShortcutWidget(QWidget *parent = 0, const char *name = 0);
00190        ~ShortcutWidget();
00191 
00192        bool event( QEvent* ev );
00193        void keyPressEvent(QKeyEvent *k);
00194        void keyReleaseEvent(QKeyEvent *k);
00195        void setKeyMap(const QMap<QString,Keys> &keymap);
00196 
00197        void setShortcut(const QString &shortcut);
00198 
00199        static QString getKeyText(int KeyC);
00200 
00201        void languageChange();
00202 
00203 public slots:
00204        void setKeyText();
00205        void setNoKey();
00206 
00207 signals:
00213        void newKey(const QString&);
00214 
00215 protected:
00216        QVBoxLayout* keyManagerLayout;
00217        QGridLayout* keyGroupLayout;
00218        QHBoxLayout* okCancelLayout;
00219 
00220        QButtonGroup* keyGroup;
00221        QRadioButton* noKey;
00222        QRadioButton* userDef;
00223        QLabel* keyDisplay;
00224        QPushButton* setKeyButton;
00225 
00226        int keyCode;
00227        QString Part0;
00228        QString Part1;
00229        QString Part2;
00230        QString Part3;
00231        QString Part4;
00232 };
00233 
00234 #endif