]> git.sven.stormbind.net Git - sven/vym.git/blob - src/flagrowmaster.cpp
Replace Pierre as the maintainer
[sven/vym.git] / src / flagrowmaster.cpp
1 #include <QDebug>
2
3 #include "flagrowmaster.h"
4 #include "mainwindow.h"
5
6 extern bool debug;
7 extern Main *mainWindow;
8
9 /////////////////////////////////////////////////////////////////
10 // FlagRowMaster
11 /////////////////////////////////////////////////////////////////
12 FlagRowMaster::FlagRowMaster()
13 {
14     // qDebug()<< "Const FlagRowMaster ()";
15     toolbar = NULL;
16     configureAction = NULL;
17 }
18
19 FlagRowMaster::~FlagRowMaster()
20 {
21     // qDebug()<< "Destr FlagRowMaster    toolbar=" << toolbar;
22 }
23
24 Flag *FlagRowMaster::createFlag(const QString &path)
25 {
26     Flag *flag = new Flag;
27     flag->load(path);
28     flags.append(flag);
29
30     return flag;
31 }
32
33 void FlagRowMaster::createConfigureAction()
34 {
35     if (!toolbar)
36         return;
37
38     QAction *a =
39         new QAction(QIcon(":/configure-plus.svg"), QString("add flag"));
40     a->setCheckable(false);
41     a->connect(a, SIGNAL(triggered()), mainWindow, SLOT(addUserFlag()));
42
43     toolbar->addAction(a);
44     configureAction = a;
45 }
46
47 void FlagRowMaster::addActionToToolbar(QAction *a)
48 {
49     if (!toolbar || !a)
50         return;
51
52     if (configureAction)
53         toolbar->insertAction(configureAction, a);
54     else
55         toolbar->addAction(a);
56 }
57
58 Flag *FlagRowMaster::findFlagByUid(const QUuid &uid)
59 {
60     int i = 0;
61     while (i <= flags.size() - 1) {
62         if (flags.at(i)->getUuid() == uid)
63             return flags.at(i);
64         i++;
65     }
66     return NULL;
67 }
68
69 Flag *FlagRowMaster::findFlagByName(const QString &name)
70 {
71     int i = 0;
72     while (i <= flags.size() - 1) {
73         if (flags.at(i)->getName() == name)
74             return flags.at(i);
75         i++;
76     }
77     qDebug() << "FR::findFlagByName failed for name " << name;
78     return NULL;
79 }
80
81 void FlagRowMaster::resetUsedCounter()
82 {
83     for (int i = 0; i < flags.size(); ++i)
84         flags.at(i)->setUsed(false);
85 }
86
87 QString FlagRowMaster::saveDef(WriteMode mode)
88 {
89     // Write definitions of flags
90
91     QString s = "\n";
92
93     for (int i = 0; i < flags.size(); ++i)
94         if ((mode == AllFlags) || (mode == UsedFlags && flags.at(i)->isUsed()))
95             s += flags.at(i)->getDefinition(prefix);
96
97     return s;
98 }
99
100 void FlagRowMaster::saveDataToDir(const QString &tmpdir, WriteMode mode)
101 {
102     // Save icons to dir, if verbose is set (xml export)
103     // and I am a master
104     // and this standardflag is really used somewhere.
105     // Userflags are written anyway (if master flagrow)
106
107     for (int i = 0; i < flags.size(); ++i)
108         if ((mode == AllFlags) || (mode == UsedFlags && flags.at(i)->isUsed()))
109             flags.at(i)->saveDataToDir(tmpdir);
110 }
111
112 void FlagRowMaster::setName(const QString &n) { rowName = n; }
113
114 void FlagRowMaster::setPrefix(const QString &p) { prefix = p; }
115
116 QString FlagRowMaster::getName() { return rowName; }
117
118 void FlagRowMaster::setToolBar(QToolBar *tb) { toolbar = tb; }
119
120 void FlagRowMaster::setEnabled(bool b) { toolbar->setEnabled(b); }
121
122 void FlagRowMaster::updateToolBar(QList<QUuid> activeUids)
123 {
124     if (toolbar) {
125         for (int i = 0; i < flags.size(); ++i)
126             flags.at(i)->getAction()->setChecked(false);
127
128         for (int i = 0; i < flags.size(); ++i) {
129             int n = activeUids.indexOf(flags.at(i)->getUuid());
130             if (n >= 0)
131                 flags.at(i)->getAction()->setChecked(true);
132         }
133     }
134 }