diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2019-01-05 21:13:04 +0100 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2019-01-05 21:13:04 +0100 |
commit | 7d9ca91c2922ede0d21a856abf61c14d9ce7898a (patch) | |
tree | 8ef1d64e680c5e0e1f36e9f0170ea36ffb43956f /src/gui | |
parent | 6760247a5ca6143779699cbd5de5022e7477bd80 (diff) |
preference dialog done (closes #50)
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/latexprocess.cpp | 57 | ||||
-rw-r--r-- | src/gui/mainmenu.cpp | 8 | ||||
-rw-r--r-- | src/gui/mainmenu.h | 3 | ||||
-rw-r--r-- | src/gui/mainmenu.ui | 16 | ||||
-rw-r--r-- | src/gui/preferencedialog.cpp | 111 | ||||
-rw-r--r-- | src/gui/preferencedialog.h | 31 | ||||
-rw-r--r-- | src/gui/preferencedialog.ui | 272 | ||||
-rw-r--r-- | src/gui/styleeditor.cpp | 34 | ||||
-rw-r--r-- | src/gui/tikzview.cpp | 8 |
9 files changed, 475 insertions, 65 deletions
diff --git a/src/gui/latexprocess.cpp b/src/gui/latexprocess.cpp index 0bda54f..d267bf5 100644 --- a/src/gui/latexprocess.cpp +++ b/src/gui/latexprocess.cpp @@ -23,6 +23,7 @@ #include <QStandardPaths> #include <QTemporaryDir> #include <QStringList> +#include <QSettings> LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(parent) { @@ -42,6 +43,7 @@ LatexProcess::LatexProcess(PreviewWindow *preview, QObject *parent) : QObject(pa void LatexProcess::makePreview(QString tikz) { + QSettings settings("tikzit", "tikzit"); _preview->setStatus(PreviewWindow::Running); _output->clear(); @@ -51,40 +53,47 @@ void LatexProcess::makePreview(QString tikz) } _output->appendPlainText("USING TEMP DIR: " + _workingDir.path() + "\n"); - _output->appendPlainText("SEARCHING FOR pdflatex IN:"); - _output->appendPlainText(qgetenv("PATH")); - _output->appendPlainText("\n"); + QString pdflatex; - QString pdflatex = QStandardPaths::findExecutable("pdflatex"); - if (pdflatex.isEmpty()) { - // if pdflatex is not in PATH, we are probably on mac or windows, so try common - // install directories. - _output->appendPlainText("NOT FOUND IN PATH, TRYING:"); - - QStringList texDirs; - // common macOS tex directories: - texDirs << "/Library/TeX/texbin"; - texDirs << "/usr/texbin"; - texDirs << "/usr/local/bin"; - texDirs << "/sw/bin"; - - // common windows tex directories - texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin"; - texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64"; - - _output->appendPlainText(texDirs.join(":")); - pdflatex = QStandardPaths::findExecutable("pdflatex", texDirs); + if (settings.value("auto-detect-pdflatex", true).toBool()) { + _output->appendPlainText("SEARCHING FOR pdflatex IN:"); + _output->appendPlainText(qgetenv("PATH")); + _output->appendPlainText("\n"); + pdflatex = QStandardPaths::findExecutable("pdflatex"); + if (pdflatex.isEmpty()) { + // if pdflatex is not in PATH, we are probably on mac or windows, so try common + // install directories. + _output->appendPlainText("NOT FOUND IN PATH, TRYING:"); + + QStringList texDirs; + // common macOS tex directories: + texDirs << "/Library/TeX/texbin"; + texDirs << "/usr/texbin"; + texDirs << "/usr/local/bin"; + texDirs << "/sw/bin"; + + // common windows tex directories + texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin"; + texDirs << "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64"; + + _output->appendPlainText(texDirs.join(":")); + pdflatex = QStandardPaths::findExecutable("pdflatex", texDirs); + } if (pdflatex.isEmpty()) { _output->appendPlainText("pdflatex NOT FOUND, ABORTING.\n"); _preview->setStatus(PreviewWindow::Failed); return; + } else { + _output->appendPlainText("FOUND: " + pdflatex + "\n"); } + } else { + _output->appendPlainText("USING pdflatex:\n"); + pdflatex = settings.value("pdflatex-path", "/usr/bin/pdflatex").toString(); + _output->appendPlainText(pdflatex + "\n"); } - _output->appendPlainText("FOUND: " + pdflatex + "\n"); - // copy tikzit.sty to preview dir QFile::copy(":/tex/sample/tikzit.sty", _workingDir.path() + "/tikzit.sty"); diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index 3b8b92b..6f4f8db 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -17,6 +17,7 @@ */ #include "mainmenu.h" +#include "preferencedialog.h" #include "tikzit.h" #include <QDebug> @@ -269,6 +270,13 @@ void MainMenu::on_actionRun_LaTeX_triggered() tikzit->makePreview(); } +void MainMenu::on_actionPreferences_triggered() +{ + PreferenceDialog *d = new PreferenceDialog(this); + d->exec(); + d->deleteLater(); +} + // View void MainMenu::on_actionZoom_In_triggered() diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h index 8acef49..4d672cd 100644 --- a/src/gui/mainmenu.h +++ b/src/gui/mainmenu.h @@ -66,11 +66,12 @@ public slots: void on_actionExtendLeft_triggered(); void on_actionExtendRight_triggered(); - // Tikz + // Tools void on_actionParse_triggered(); void on_actionRevert_triggered(); void on_actionJump_to_Selection_triggered(); void on_actionRun_LaTeX_triggered(); + void on_actionPreferences_triggered(); // View void on_actionZoom_In_triggered(); diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index 097430c..54b02f8 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -75,12 +75,14 @@ </widget> <widget class="QMenu" name="menuTikz"> <property name="title"> - <string>Tikz</string> + <string>Tools</string> </property> <addaction name="actionParse"/> <addaction name="actionRevert"/> <addaction name="actionJump_to_Selection"/> <addaction name="actionRun_LaTeX"/> + <addaction name="separator"/> + <addaction name="actionPreferences"/> </widget> <widget class="QMenu" name="menuView"> <property name="title"> @@ -204,7 +206,7 @@ </action> <action name="actionParse"> <property name="text"> - <string>Parse Tikz</string> + <string>Parse TikZ</string> </property> <property name="shortcut"> <string>Ctrl+T</string> @@ -233,7 +235,10 @@ </action> <action name="actionRevert"> <property name="text"> - <string>Revert Tikz</string> + <string>Revert TikZ</string> + </property> + <property name="shortcut"> + <string>Ctrl+Alt+T</string> </property> </action> <action name="actionJump_to_Selection"> @@ -355,6 +360,11 @@ <string>Clear Menu</string> </property> </action> + <action name="actionPreferences"> + <property name="text"> + <string>Preferences...</string> + </property> + </action> <addaction name="menuFile"/> <addaction name="menuEdit"/> <addaction name="menuView"/> diff --git a/src/gui/preferencedialog.cpp b/src/gui/preferencedialog.cpp new file mode 100644 index 0000000..06159af --- /dev/null +++ b/src/gui/preferencedialog.cpp @@ -0,0 +1,111 @@ +#include "preferencedialog.h" +#include "ui_preferencedialog.h" + +#include <QColorDialog> +#include <QFileDialog> +#include <QSettings> + +PreferenceDialog::PreferenceDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::PreferenceDialog) +{ + ui->setupUi(this); + QSettings settings("tikzit", "tikzit"); + ui->autoPdflatex->setChecked(true); + + if (!settings.value("auto-detect-pdflatex").isNull()) + ui->autoPdflatex->setChecked(settings.value("auto-detect-pdflatex").toBool()); + if (!settings.value("pdflatex-path").isNull()) + ui->pdflatexPath->setText(settings.value("pdflatex-path").toString()); + + + setColor(ui->axesColor, settings.value("grid-color-axes", + QColor(220,220,240)).value<QColor>()); + setColor(ui->majorColor, settings.value("grid-color-major", + QColor(240,240,250)).value<QColor>()); + setColor(ui->minorColor, settings.value("grid-color-minor", + QColor(250,250,255)).value<QColor>()); + + + connect(ui->axesColor, SIGNAL(clicked()), this, SLOT(colorClick())); + connect(ui->majorColor, SIGNAL(clicked()), this, SLOT(colorClick())); + connect(ui->minorColor, SIGNAL(clicked()), this, SLOT(colorClick())); +} + +PreferenceDialog::~PreferenceDialog() +{ + delete ui; +} + +void PreferenceDialog::accept() +{ + QSettings settings("tikzit", "tikzit"); + settings.setValue("auto-detect-pdflatex", ui->autoPdflatex->isChecked()); + settings.setValue("pdflatex-path", ui->pdflatexPath->text()); + settings.setValue("grid-color-axes", color(ui->axesColor)); + settings.setValue("grid-color-major", color(ui->majorColor)); + settings.setValue("grid-color-minor", color(ui->minorColor)); + QDialog::accept(); +} + +void PreferenceDialog::on_resetColors_clicked() +{ + setColor(ui->axesColor, QColor(220,220,240)); + setColor(ui->majorColor, QColor(240,240,250)); + setColor(ui->minorColor, QColor(250,250,255)); +} + +void PreferenceDialog::colorClick() +{ + if (QPushButton *btn = dynamic_cast<QPushButton*>(sender())) { + QColor col = QColorDialog::getColor( + color(btn), + this, + "Set color", + QColorDialog::DontUseNativeDialog); + if (col.isValid()) setColor(btn, col); + } +} + +void PreferenceDialog::on_autoPdflatex_stateChanged(int state) +{ + ui->pdflatexPath->setEnabled(state != Qt::Checked); + ui->browsePdflatex->setEnabled(state != Qt::Checked); +} + +void PreferenceDialog::on_browsePdflatex_clicked() +{ + QSettings settings("tikzit", "tikzit"); + + QFileDialog dialog; + dialog.setWindowTitle(tr("pdflatex Path")); + dialog.setAcceptMode(QFileDialog::AcceptOpen); + dialog.setFileMode(QFileDialog::ExistingFile); + dialog.setLabelText(QFileDialog::Accept, "Select"); + + QFileInfo fi(ui->pdflatexPath->text()); + if (!fi.absolutePath().isEmpty()) { + dialog.setDirectory(fi.absolutePath()); + dialog.selectFile(fi.baseName()); + } + + dialog.setOption(QFileDialog::DontUseNativeDialog); + + if (dialog.exec()) { + ui->pdflatexPath->setText(QDir::toNativeSeparators(dialog.selectedFiles()[0])); + } +} + +void PreferenceDialog::setColor(QPushButton *btn, QColor col) +{ + QPalette pal = btn->palette(); + pal.setColor(QPalette::Button, col); + btn->setPalette(pal); + btn->update(); +} + +QColor PreferenceDialog::color(QPushButton *btn) +{ + QPalette pal = btn->palette(); + return pal.color(QPalette::Button); +} diff --git a/src/gui/preferencedialog.h b/src/gui/preferencedialog.h new file mode 100644 index 0000000..9da8ae6 --- /dev/null +++ b/src/gui/preferencedialog.h @@ -0,0 +1,31 @@ +#ifndef PREFERENCEDIALOG_H +#define PREFERENCEDIALOG_H + +#include <QDialog> + +namespace Ui { +class PreferenceDialog; +} + +class PreferenceDialog : public QDialog +{ + Q_OBJECT + +public: + explicit PreferenceDialog(QWidget *parent = nullptr); + ~PreferenceDialog() override; + +protected slots: + void accept() override; + void colorClick(); + void on_resetColors_clicked(); + void on_autoPdflatex_stateChanged(int state); + void on_browsePdflatex_clicked(); + +private: + Ui::PreferenceDialog *ui; + QColor color(QPushButton *btn); + void setColor(QPushButton *btn, QColor col); +}; + +#endif // PREFERENCEDIALOG_H diff --git a/src/gui/preferencedialog.ui b/src/gui/preferencedialog.ui new file mode 100644 index 0000000..9a32e7d --- /dev/null +++ b/src/gui/preferencedialog.ui @@ -0,0 +1,272 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PreferenceDialog</class> + <widget class="QDialog" name="PreferenceDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>345</width> + <height>176</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>pdflatex Location</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLineEdit" name="pdflatexPath"/> + </item> + <item> + <widget class="QToolButton" name="browsePdflatex"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="1"> + <widget class="QCheckBox" name="autoPdflatex"> + <property name="text"> + <string>Automatically detect pdflatex</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Grid colors</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QFrame" name="frame"> + <property name="frameShape"> + <enum>QFrame::Box</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Plain</enum> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QPushButton" name="axesColor"> + <property name="autoFillBackground"> + <bool>true</bool> + </property> + <property name="text"> + <string/> + </property> + <property name="flat"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Axes</string> + </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> + <item> + <widget class="QFrame" name="frame_2"> + <property name="frameShape"> + <enum>QFrame::Box</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Plain</enum> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QPushButton" name="majorColor"> + <property name="autoFillBackground"> + <bool>true</bool> + </property> + <property name="text"> + <string/> + </property> + <property name="flat"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Major</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <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="QFrame" name="frame_3"> + <property name="frameShape"> + <enum>QFrame::Box</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Plain</enum> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QPushButton" name="minorColor"> + <property name="autoFillBackground"> + <bool>true</bool> + </property> + <property name="text"> + <string/> + </property> + <property name="flat"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Minor</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="3" column="1"> + <widget class="QPushButton" name="resetColors"> + <property name="text"> + <string>Reset colors</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>PreferenceDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>PreferenceDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp index 7817731..e2ade45 100644 --- a/src/gui/styleeditor.cpp +++ b/src/gui/styleeditor.cpp @@ -72,40 +72,6 @@ StyleEditor::StyleEditor(QWidget *parent) : SIGNAL(currentIndexChanged(int)), this, SLOT(shapeChanged())); - // setup the color dialog to display only the named colors that tikzit/xcolor knows - // about as "standard colors". - for (int i = 0; i < 48; ++i) { - QColorDialog::setStandardColor(i, QColor(Qt::white)); - } - - // grayscale in column 1 - int pos = 0; - for (int i=0; i < 5; ++i) { - QColorDialog::setStandardColor(pos, tikzit->colorByIndex(i)); - pos += 1; - } - - // rainbow in column 2 - pos = 6; - for (int i=5; i < 11; ++i) { - QColorDialog::setStandardColor(pos, tikzit->colorByIndex(i)); - pos += 1; - } - - // brown/green/teal spectrum in column 3 - pos = 12; - for (int i=11; i < 16; ++i) { - QColorDialog::setStandardColor(pos, tikzit->colorByIndex(i)); - pos += 1; - } - - // pinks in column 4 - pos = 18; - for (int i=16; i < 19; ++i) { - QColorDialog::setStandardColor(pos, tikzit->colorByIndex(i)); - pos += 1; - } - refreshDisplay(); } diff --git a/src/gui/tikzview.cpp b/src/gui/tikzview.cpp index 52a32cf..5b0f09c 100644 --- a/src/gui/tikzview.cpp +++ b/src/gui/tikzview.cpp @@ -21,6 +21,7 @@ #include <QDebug> #include <QScrollBar> +#include <QSettings> TikzView::TikzView(QWidget *parent) : QGraphicsView(parent) { @@ -53,6 +54,7 @@ void TikzView::setScene(QGraphicsScene *scene) void TikzView::drawBackground(QPainter *painter, const QRectF &rect) { + QSettings settings("tikzit", "tikzit"); QGraphicsView::drawBackground(painter, rect); // draw a gray background if disabled TikzScene *sc = static_cast<TikzScene*>(scene()); @@ -63,13 +65,13 @@ void TikzView::drawBackground(QPainter *painter, const QRectF &rect) QPen pen1; //pen1.setWidthF(0.5); pen1.setCosmetic(true); - pen1.setColor(QColor(250,250,255)); + pen1.setColor(settings.value("grid-color-minor", QColor(250,250,255)).value<QColor>()); QPen pen2 = pen1; - pen2.setColor(QColor(240,240,250)); + pen2.setColor(settings.value("grid-color-major", QColor(240,240,250)).value<QColor>()); QPen pen3 = pen1; - pen3.setColor(QColor(220,220,240)); + pen3.setColor(settings.value("grid-color-axes", QColor(220,220,240)).value<QColor>()); painter->setPen(pen1); |