From 7d9ca91c2922ede0d21a856abf61c14d9ce7898a Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 5 Jan 2019 21:13:04 +0100 Subject: preference dialog done (closes #50) --- src/gui/latexprocess.cpp | 57 +++++---- src/gui/mainmenu.cpp | 8 ++ src/gui/mainmenu.h | 3 +- src/gui/mainmenu.ui | 16 ++- src/gui/preferencedialog.cpp | 111 ++++++++++++++++++ src/gui/preferencedialog.h | 31 +++++ src/gui/preferencedialog.ui | 272 +++++++++++++++++++++++++++++++++++++++++++ src/gui/styleeditor.cpp | 34 ------ src/gui/tikzview.cpp | 8 +- src/tikzit.cpp | 134 +++++++++++++-------- src/tikzit.h | 6 +- tikzit.pro | 9 +- 12 files changed, 572 insertions(+), 117 deletions(-) create mode 100644 src/gui/preferencedialog.cpp create mode 100644 src/gui/preferencedialog.h create mode 100644 src/gui/preferencedialog.ui 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 #include #include +#include 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 @@ -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 @@ - Tikz + Tools + + @@ -204,7 +206,7 @@ - Parse Tikz + Parse TikZ Ctrl+T @@ -233,7 +235,10 @@ - Revert Tikz + Revert TikZ + + + Ctrl+Alt+T @@ -355,6 +360,11 @@ Clear Menu + + + Preferences... + + 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 +#include +#include + +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()); + setColor(ui->majorColor, settings.value("grid-color-major", + QColor(240,240,250)).value()); + setColor(ui->minorColor, settings.value("grid-color-minor", + QColor(250,250,255)).value()); + + + 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(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 + +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 @@ + + + PreferenceDialog + + + + 0 + 0 + 345 + 176 + + + + Dialog + + + + + + + + pdflatex Location + + + + + + + + + + + + ... + + + + + + + + + Automatically detect pdflatex + + + + + + + Grid colors + + + + + + + + + QFrame::Box + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + + + true + + + + + + + + + + Axes + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QFrame::Box + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + + + true + + + + + + + + + + Major + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QFrame::Box + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + + + true + + + + + + + + + + Minor + + + + + + + + + Reset colors + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PreferenceDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PreferenceDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + 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 #include +#include 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(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()); QPen pen2 = pen1; - pen2.setColor(QColor(240,240,250)); + pen2.setColor(settings.value("grid-color-major", QColor(240,240,250)).value()); QPen pen3 = pen1; - pen3.setColor(QColor(220,220,240)); + pen3.setColor(settings.value("grid-color-axes", QColor(220,220,240)).value()); painter->setPen(pen1); diff --git a/src/tikzit.cpp b/src/tikzit.cpp index 2e36b21..2a7c00a 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -30,6 +30,7 @@ #include #include #include +#include // application-level instance of Tikzit Tikzit *tikzit; @@ -45,54 +46,7 @@ void Tikzit::init() { QSettings settings("tikzit", "tikzit"); - // 19 standard xcolor colours - _colNames << - "black" << - "darkgray" << - "gray" << - "lightgray" << - "white" << - - "red" << - "orange" << - "yellow" << - "green" << - "blue" << - "purple" << - - "brown" << - "olive" << - "lime" << - "cyan" << - "teal" << - - "magenta" << - "violet" << - "pink"; - - _cols << - QColor::fromRgbF(0,0,0) << - QColor::fromRgbF(0.25,0.25,0.25) << - QColor::fromRgbF(0.5,0.5,0.5) << - QColor::fromRgbF(0.75,0.75,0.75) << - QColor::fromRgbF(1,1,1) << - - QColor::fromRgbF(1,0,0) << - QColor::fromRgbF(1,0.5,0) << - QColor::fromRgbF(1,1,0) << - QColor::fromRgbF(0,1,0) << - QColor::fromRgbF(0,0,1) << - QColor::fromRgbF(0.75,0,0.25) << - - QColor::fromRgbF(0.75,0.5,0.25) << - QColor::fromRgbF(0.5,0.5,0) << - QColor::fromRgbF(0.75,1,0) << - QColor::fromRgbF(0,1,1) << - QColor::fromRgbF(0,0.5,0.5) << - - QColor::fromRgbF(1,0,1) << - QColor::fromRgbF(0.5,0,0.5) << - QColor::fromRgbF(1,0.75,0.75); + initColors(); _mainMenu = new MainMenu(); QMainWindow *dummy = new QMainWindow(); @@ -489,6 +443,90 @@ void Tikzit::cleanupLatex() } } +void Tikzit::initColors() +{ + // 19 standard xcolor colours + _colNames << + "black" << + "darkgray" << + "gray" << + "lightgray" << + "white" << + + "red" << + "orange" << + "yellow" << + "green" << + "blue" << + "purple" << + + "brown" << + "olive" << + "lime" << + "cyan" << + "teal" << + + "magenta" << + "violet" << + "pink"; + + _cols << + QColor::fromRgbF(0,0,0) << + QColor::fromRgbF(0.25,0.25,0.25) << + QColor::fromRgbF(0.5,0.5,0.5) << + QColor::fromRgbF(0.75,0.75,0.75) << + QColor::fromRgbF(1,1,1) << + + QColor::fromRgbF(1,0,0) << + QColor::fromRgbF(1,0.5,0) << + QColor::fromRgbF(1,1,0) << + QColor::fromRgbF(0,1,0) << + QColor::fromRgbF(0,0,1) << + QColor::fromRgbF(0.75,0,0.25) << + + QColor::fromRgbF(0.75,0.5,0.25) << + QColor::fromRgbF(0.5,0.5,0) << + QColor::fromRgbF(0.75,1,0) << + QColor::fromRgbF(0,1,1) << + QColor::fromRgbF(0,0.5,0.5) << + + QColor::fromRgbF(1,0,1) << + QColor::fromRgbF(0.5,0,0.5) << + QColor::fromRgbF(1,0.75,0.75); + + 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, _cols[i]); + pos += 1; + } + + // rainbow in column 2 + pos = 6; + for (int i=5; i < 11; ++i) { + QColorDialog::setStandardColor(pos, _cols[i]); + pos += 1; + } + + // brown/green/teal spectrum in column 3 + pos = 12; + for (int i=11; i < 16; ++i) { + QColorDialog::setStandardColor(pos, _cols[i]); + pos += 1; + } + + // pinks in column 4 + pos = 18; + for (int i=16; i < 19; ++i) { + QColorDialog::setStandardColor(pos, _cols[i]); + pos += 1; + } +} + PreviewWindow *Tikzit::previewWindow() const { return _preview; diff --git a/src/tikzit.h b/src/tikzit.h index 6249b9e..4797f48 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -149,7 +149,11 @@ public slots: void cleanupLatex(); private: - // void createMenu(); + /*! + * \brief initColors initialises a table of xcolor named colors and their associated + * QColor values, and adds them as standard colors to the Qt color dialog. + */ + void initColors(); MainMenu *_mainMenu; ToolPalette *_toolPalette; diff --git a/tikzit.pro b/tikzit.pro index ed1fca6..692433d 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -81,7 +81,8 @@ SOURCES += src/gui/mainwindow.cpp \ src/data/pdfdocument.cpp \ src/gui/exportdialog.cpp \ src/data/delimitedstringvalidator.cpp \ - src/gui/delimitedstringitemdelegate.cpp + src/gui/delimitedstringitemdelegate.cpp \ + src/gui/preferencedialog.cpp HEADERS += src/gui/mainwindow.h \ src/gui/toolpalette.h \ @@ -113,7 +114,8 @@ HEADERS += src/gui/mainwindow.h \ src/data/pdfdocument.h \ src/gui/exportdialog.h \ src/data/delimitedstringvalidator.h \ - src/gui/delimitedstringitemdelegate.h + src/gui/delimitedstringitemdelegate.h \ + src/gui/preferencedialog.h FORMS += src/gui/mainwindow.ui \ src/gui/propertypalette.ui \ @@ -121,7 +123,8 @@ FORMS += src/gui/mainwindow.ui \ src/gui/stylepalette.ui \ src/gui/styleeditor.ui \ src/gui/previewwindow.ui \ - src/gui/exportdialog.ui + src/gui/exportdialog.ui \ + src/gui/preferencedialog.ui INCLUDEPATH += src src/gui src/data -- cgit v1.2.3