Make it work for files also
[kugel-rb.git] / utils / themeeditor / gui / skindocument.h
blobf7ac2bbc2c3c38c4de6ea999b588090839fc496a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Robert Bieber
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef SKINDOCUMENT_H
23 #define SKINDOCUMENT_H
25 #include <QWidget>
26 #include <QLabel>
27 #include <QHBoxLayout>
28 #include <QGraphicsScene>
29 #include <QTime>
30 #include <QTimer>
32 #include "findreplacedialog.h"
34 #include "skinhighlighter.h"
35 #include "parsetreemodel.h"
36 #include "preferencesdialog.h"
37 #include "codeeditor.h"
38 #include "tabcontent.h"
39 #include "projectmodel.h"
40 #include "devicestate.h"
42 class SkinDocument : public TabContent
44 Q_OBJECT
45 public:
46 static QString fileFilter()
48 return tr("WPS Files (*.wps *.rwps);;"
49 "SBS Files (*.sbs *.rsbs);;"
50 "FMS Files (*.fms *.rfms);;"
51 "All Skin Files (*.wps *.rwps *.sbs "
52 "*.rsbs *.fms *.rfms);;"
53 "All Files (*.*)");
56 SkinDocument(QLabel* statusLabel, ProjectModel* project = 0,
57 DeviceState* device = 0, QWidget *parent = 0);
58 SkinDocument(QLabel* statusLabel, QString file, ProjectModel* project = 0,
59 DeviceState* device = 0, QWidget* parent = 0);
60 virtual ~SkinDocument();
62 void connectPrefs(PreferencesDialog* prefs);
64 ParseTreeModel* getModel(){ return model; }
65 QString file() const{ return fileName; }
66 QString title() const{ return titleText; }
67 QString getStatus(){ return parseStatus; }
68 CodeEditor* getEditor(){ return editor; }
69 void genCode(){ editor->document()->setPlainText(model->genCode()); }
70 void setProject(ProjectModel* project){ this->project = project; }
72 void save();
73 void saveAs();
75 bool requestClose();
77 TabType type() const{ return Skin; }
79 QGraphicsScene* scene(){ return model->render(project, device, &fileName); }
81 void showFind(){ findReplace->show(); }
82 void hideFind(){ findReplace->hide(); }
84 signals:
86 public slots:
87 void settingsChanged();
88 void cursorChanged();
90 private slots:
91 void codeChanged();
92 void deviceChanged(){ scene(); }
94 private:
95 void setupUI();
96 QString findSetting(QString key, QString fallback);
98 QString titleText;
99 QString fileName;
100 QString saved;
101 QString parseStatus;
102 int currentLine;
104 QLayout* layout;
105 CodeEditor* editor;
107 SkinHighlighter* highlighter;
108 ParseTreeModel* model;
110 QLabel* statusLabel;
112 bool blockUpdate;
114 ProjectModel* project;
115 DeviceState* device;
117 FindReplaceDialog* findReplace;
119 QTime lastUpdate;
120 static const int updateInterval;
121 QTimer checkUpdate;
124 #endif // SKINDOCUMENT_H