summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-10-08 14:14:54 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-10-08 14:14:54 +0200
commit59f92c45fd751aeb7811ca68d76d3af4ee72a9c4 (patch)
treea5bb618f72dd7bb286f5799d94f7e1322035c1f0
parente0f973435c6cf24f4eefc9f767b8b6a957daf8ac (diff)
anchor to center
-rw-r--r--src/gui/mainwindow.cpp22
-rw-r--r--src/gui/styleeditor.cpp45
-rw-r--r--src/gui/styleeditor.h2
-rw-r--r--src/gui/stylepalette.cpp7
-rw-r--r--src/gui/stylepalette.h1
-rw-r--r--src/gui/stylepalette.ui62
-rw-r--r--src/gui/tikzview.cpp3
-rw-r--r--src/gui/toolpalette.cpp1
8 files changed, 111 insertions, 32 deletions
diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp
index f9743a1..cdf7bea 100644
--- a/src/gui/mainwindow.cpp
+++ b/src/gui/mainwindow.cpp
@@ -23,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
+ QSettings settings("tikzit", "tikzit");
_windowId = _numWindows;
_numWindows++;
ui->setupUi(this);
@@ -36,8 +37,6 @@ MainWindow::MainWindow(QWidget *parent) :
addToolBar(_toolPalette);
_stylePalette = new StylePalette(this);
- addDockWidget(Qt::RightDockWidgetArea, _stylePalette);
- resizeDocks({_stylePalette}, {130}, Qt::Horizontal);
_tikzScene = new TikzScene(_tikzDocument, _toolPalette, _stylePalette, this);
ui->tikzView->setScene(_tikzScene);
@@ -48,6 +47,20 @@ MainWindow::MainWindow(QWidget *parent) :
setMenuBar(_menu);
+ QVariant geom = settings.value("geometry-main");
+ QVariant state = settings.value("windowState-main");
+
+ if (geom.isValid()) {
+ restoreGeometry(geom.toByteArray());
+ }
+
+ if (state.isValid()) {
+ restoreState(state.toByteArray(), 2);
+ } else {
+ addDockWidget(Qt::RightDockWidgetArea, _stylePalette);
+ resizeDocks({_stylePalette}, {130}, Qt::Horizontal);
+ }
+
// initially, the source view should be collapsed
QList<int> sz = ui->splitter->sizes();
sz[0] = sz[0] + sz[1];
@@ -90,6 +103,11 @@ QSplitter *MainWindow::splitter() const {
void MainWindow::closeEvent(QCloseEvent *event)
{
qDebug() << "got close event";
+
+ QSettings settings("tikzit", "tikzit");
+ settings.setValue("geometry-main", saveGeometry());
+ settings.setValue("windowState-main", saveState(2));
+
QMainWindow::closeEvent(event);
}
diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp
index 06bb718..36ae93a 100644
--- a/src/gui/styleeditor.cpp
+++ b/src/gui/styleeditor.cpp
@@ -442,6 +442,39 @@ void StyleEditor::on_propertyDown_clicked()
}
}
+void StyleEditor::on_addStyle_clicked()
+{
+ int i = 0;
+
+ // get a fresh name
+ QString name;
+ while (true) {
+ name = QString("new style ") + QString::number(i);
+ if (_styles->nodeStyles()->style(name) == nullptr) break;
+ ++i;
+ }
+
+ // add the style to the current category
+ Style *s;
+ if (_styles->nodeStyles()->category() == "") {
+ s = new Style(name, new GraphElementData());
+ } else {
+ s = new Style(name,
+ new GraphElementData({
+ GraphElementProperty("category",_styles->nodeStyles()->category())
+ }));
+ }
+ _styles->nodeStyles()->addStyle(s);
+
+ // set dirty flag and select the newly-added style
+ _dirty = true;
+// ui->styleListView->selectionModel()->clear();
+// ui->edgeStyleListView->selectionModel()->clear();
+ ui->styleListView->selectionModel()->setCurrentIndex(
+ _styles->nodeStyles()->index(_styles->nodeStyles()->numInCategory()-1),
+ QItemSelectionModel::ClearAndSelect);
+}
+
void StyleEditor::on_save_clicked()
{
save();
@@ -540,11 +573,19 @@ Style *StyleEditor::activeStyle()
void StyleEditor::refreshActiveStyle()
{
if (_styles != nullptr) {
- if (_nodeStyleIndex.isValid())
+ if (_nodeStyleIndex.isValid()) {
emit _styles->nodeStyles()->dataChanged(_nodeStyleIndex, _nodeStyleIndex);
- if (_edgeStyleIndex.isValid())
+ // force a re-layout
+ ui->styleListView->setGridSize(QSize(48,48));
+ }
+
+ if (_edgeStyleIndex.isValid()) {
emit _styles->edgeStyles()->dataChanged(_edgeStyleIndex, _edgeStyleIndex);
+
+ // force a re-layout
+ ui->edgeStyleListView->setGridSize(QSize(48,48));
+ }
}
}
diff --git a/src/gui/styleeditor.h b/src/gui/styleeditor.h
index f9caf9c..bc548f0 100644
--- a/src/gui/styleeditor.h
+++ b/src/gui/styleeditor.h
@@ -48,6 +48,8 @@ public slots:
void on_propertyUp_clicked();
void on_propertyDown_clicked();
+ void on_addStyle_clicked();
+
void on_save_clicked();
void on_currentCategory_currentIndexChanged(int);
diff --git a/src/gui/stylepalette.cpp b/src/gui/stylepalette.cpp
index 953d9d5..5e6de43 100644
--- a/src/gui/stylepalette.cpp
+++ b/src/gui/stylepalette.cpp
@@ -174,3 +174,10 @@ void StylePalette::closeEvent(QCloseEvent *event)
settings.setValue("style-palette-geometry", saveGeometry());
QDockWidget::closeEvent(event);
}
+
+void StylePalette::resizeEvent(QResizeEvent *event)
+{
+ QDockWidget::resizeEvent(event);
+ ui->styleListView->setGridSize(QSize(48,48));
+ ui->edgeStyleListView->setGridSize(QSize(48,48));
+}
diff --git a/src/gui/stylepalette.h b/src/gui/stylepalette.h
index 7cdef0c..b76aa03 100644
--- a/src/gui/stylepalette.h
+++ b/src/gui/stylepalette.h
@@ -56,6 +56,7 @@ private:
protected:
void closeEvent(QCloseEvent *event) override;
+ void resizeEvent(QResizeEvent *event) override;
};
#endif // STYLEPALETTE_H
diff --git a/src/gui/stylepalette.ui b/src/gui/stylepalette.ui
index abba648..39e796b 100644
--- a/src/gui/stylepalette.ui
+++ b/src/gui/stylepalette.ui
@@ -32,11 +32,29 @@
<bool>false</bool>
</property>
<property name="windowTitle">
- <string/>
+ <string>Styles</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
+ <widget class="QLabel" name="styleFile">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <italic>true</italic>
+ </font>
+ </property>
+ <property name="text">
+ <string>[default]</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>2</number>
@@ -45,19 +63,6 @@
<number>0</number>
</property>
<item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
<widget class="QToolButton" name="buttonOpenTikzstyles">
<property name="toolTip">
<string>Load Styles</string>
@@ -99,22 +104,22 @@
</property>
</widget>
</item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
</layout>
</item>
<item>
- <widget class="QLabel" name="styleFile">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>[default]</string>
- </property>
- </widget>
- </item>
- <item>
<widget class="QComboBox" name="currentCategory"/>
</item>
<item>
@@ -131,6 +136,9 @@
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
+ <property name="resizeMode">
+ <enum>QListView::Adjust</enum>
+ </property>
</widget>
</item>
<item>
diff --git a/src/gui/tikzview.cpp b/src/gui/tikzview.cpp
index 0f1dc30..3f107be 100644
--- a/src/gui/tikzview.cpp
+++ b/src/gui/tikzview.cpp
@@ -25,6 +25,7 @@
TikzView::TikzView(QWidget *parent) : QGraphicsView(parent)
{
setRenderHint(QPainter::Antialiasing);
+ setResizeAnchor(QGraphicsView::AnchorViewCenter);
//setDragMode(QGraphicsView::RubberBandDrag);
_scale = 1.0f;
@@ -45,7 +46,7 @@ void TikzView::zoomOut()
void TikzView::setScene(QGraphicsScene *scene)
{
QGraphicsView::setScene(scene);
- centerOn(QPointF(0.0f,-230.0f));
+ centerOn(QPointF(0.0f,0.0f));
}
void TikzView::drawBackground(QPainter *painter, const QRectF &rect)
diff --git a/src/gui/toolpalette.cpp b/src/gui/toolpalette.cpp
index c0e2a22..2452bda 100644
--- a/src/gui/toolpalette.cpp
+++ b/src/gui/toolpalette.cpp
@@ -31,6 +31,7 @@ ToolPalette::ToolPalette(QWidget *parent) :
| Qt::WindowDoesNotAcceptFocus);
setOrientation(Qt::Vertical);
setFocusPolicy(Qt::NoFocus);
+ setWindowTitle("Tools");
//setGeometry(100,200,30,195);
tools = new QActionGroup(this);