1 /***************************************************************************
2  *   file klfstylemanager.h
3  *   This file is part of the KLatexFormula Project.
4  *   Copyright (C) 2011 by Philippe Faist
5  *   philippe.faist@bluewin.ch
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU General Public License as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  *   This program is distributed in the hope that it will be useful,       *
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15  *   GNU General Public License for more details.                          *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License     *
18  *   along with this program; if not, write to the                         *
19  *   Free Software Foundation, Inc.,                                       *
20  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
21  ***************************************************************************/
22 /* $Id: klfstylemanager.h 604 2011-02-27 23:34:37Z phfaist $ */
23 
24 #ifndef KLFSTYLEMANAGER_H
25 #define KLFSTYLEMANAGER_H
26 
27 #include <QWidget>
28 #include <QMenu>
29 #include <QListWidget>
30 #include <QStringListModel>
31 
32 //#include <klfdata.h>
33 #include <klflib.h>
34 
35 namespace Ui { class KLFStyleManager; }
36 
37 class KLFStyleListModel : public QStringListModel
38 {
39   Q_OBJECT
40 public:
QStringListModel(parent)41   KLFStyleListModel(QObject *parent = 0) : QStringListModel(parent) { }
~KLFStyleListModel()42   virtual ~KLFStyleListModel() { }
43 
44   virtual Qt::ItemFlags flags(const QModelIndex& index) const;
45 
46   virtual QString styleName(int row) const;
47   virtual void setStyleName(int row, const QString& newname);
48 
49   Qt::DropActions supportedDropActions() const;
50   QStringList mimeTypes() const;
51   QMimeData *mimeData(const QModelIndexList& indexes) const;
52   bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
53 		    int column, const QModelIndex &parent);
54 
55 signals:
56   void internalMoveCompleted(int prevrow, int newrow);
57 };
58 
59 
60 class KLFStyleManager : public QWidget
61 {
62   Q_OBJECT
63 public:
64   KLFStyleManager(KLFStyleList *ptr, QWidget *parent);
65   ~KLFStyleManager();
66 
67 signals:
68   void refreshStyles();
69 
70 public slots:
71 
72   void slotRefresh();
73 
74   void slotDelete();
75   void slotMoveUp();
76   void slotMoveDown();
77   void slotRename();
78 
79   void refreshActionsEnabledState();
80   void showActionsContextMenu(const QPoint& pos);
81 
82   void retranslateUi(bool alsoBaseUi = true);
83 
84 protected slots:
85   void slotModelMoveCompleted(int previouspos, int newpos);
86 
87 private:
88   Ui::KLFStyleManager *u;
89 
90   KLFStyleList *_styptr;
91 
92   QMenu *mActionsPopup;
93 
94   QAction *actPopupDelete;
95   QAction *actPopupMoveUp;
96   QAction *actPopupMoveDown;
97   QAction *actPopupRename;
98 
99   KLFStyleListModel *mStyleListModel;
100 
101   QPoint _drag_init_pos;
102   QListWidgetItem *_drag_item;
103 
104   int currentRow();
105 };
106 
107 #endif
108 
109