Commit 7d9ca91c authored by Aleks Kissinger's avatar Aleks Kissinger

preference dialog done (closes #50)

parent 6760247a
......@@ -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");
......
......@@ -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()
......
......@@ -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();
......
......@@ -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"/>
......
#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);
}
#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
<?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>
......@@ -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();
}
......
......@@ -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);
......
......@@ -30,6 +30,7 @@
#include <QRegularExpression>
#include <QVersionNumber>
#include <QNetworkAccessManager>
#include <QColorDialog>
// 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" <<