Skip to content

Commit d43c899

Browse files
committed
Add advanced option to set the ppi
1 parent 0842c15 commit d43c899

File tree

11 files changed

+201
-14
lines changed

11 files changed

+201
-14
lines changed

JASP-Desktop/mainwindow.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ void MainWindow::makeConnections()
225225
connect(ui->tabBar, &TabBar::setExactPValuesHandler, _resultsJsInterface, &ResultsJsInterface::setExactPValuesHandler );
226226
connect(ui->tabBar, &TabBar::setFixDecimalsHandler, _resultsJsInterface, &ResultsJsInterface::setFixDecimalsHandler );
227227
connect(ui->tabBar, &TabBar::emptyValuesChangedHandler, this, &MainWindow::emptyValuesChangedHandler );
228+
connect(ui->tabBar, &TabBar::useDefaultPPIHandler, _resultsJsInterface, &ResultsJsInterface::getDefaultPPI );
229+
connect(ui->tabBar, &TabBar::setPPIHandler, this, &MainWindow::setPPIHandler );
228230

229231
connect(&_loader, &AsyncLoader::progress, this, &MainWindow::setProgressStatus );
230232

@@ -329,7 +331,6 @@ void MainWindow::loadQML()
329331
qmlProgressBar = ui->quickWidget_Data->rootObject()->findChild<QObject*>("progressBarHolder");
330332
}
331333

332-
333334
void MainWindow::open(QString filepath)
334335
{
335336
_openedUsingArgs = true;
@@ -585,6 +586,13 @@ void MainWindow::dataSetChanged(DataSet * dataSet)
585586
setDataSetAndPackageInModels(_package);
586587
}
587588

589+
void MainWindow::setPPIHandler(int ppi)
590+
{
591+
emit ppiChanged(ppi);
592+
593+
refreshAllAnalyses();
594+
}
595+
588596
void MainWindow::setDataSetAndPackageInModels(DataSetPackage *package)
589597
{
590598
DataSet * dataSet = package == NULL ? NULL : package->dataSet();
@@ -1353,6 +1361,16 @@ void MainWindow::resultsPageLoaded(bool success, int ppi)
13531361
if (_engineSync->engineStarted() == false)
13541362
_engineSync->start();
13551363

1364+
PreferencesDialog *rd = ui->tabBar->getPreferencesDialog();
1365+
rd->setDefaultPPI(ppi);
1366+
1367+
bool useDefaultPPI = Settings::value(Settings::PPI_USE_DEFAULT).toBool();
1368+
if (!useDefaultPPI)
1369+
{
1370+
int customPPI = Settings::value(Settings::PPI_CUSTOM_VALUE).toInt();
1371+
ppi = customPPI;
1372+
}
1373+
13561374
emit ppiChanged(ppi);
13571375
}
13581376

JASP-Desktop/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ private slots:
173173
void updateExcludeKey();
174174
void dataSetChanged(DataSet * dataSet);
175175

176+
void setPPIHandler(int ppi);
176177

177178
private:
178179
typedef std::map<Analysis*, AnalysisForm*> analysisFormMap;

JASP-Desktop/preferencesdialog.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) :
4141
if (spreadsheetEditorName != "")
4242
ui->spreadsheetEditorName->setText(spreadsheetEditorName);
4343

44+
//PPI
45+
bool useDefaultPPI = Settings::value(Settings::PPI_USE_DEFAULT).toBool();
46+
ui->useDefaultPPI->setChecked(useDefaultPPI);
47+
QString customPPI = Settings::value(Settings::PPI_CUSTOM_VALUE).toString();
48+
ui->customPPI->setText(customPPI);
49+
50+
ui->customPPI->setEnabled(!useDefaultPPI);
51+
4452
// Remove Question mark Help sign (Only on windows )
4553
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
4654

@@ -63,6 +71,13 @@ PreferencesDialog::~PreferencesDialog()
6371
delete ui;
6472
}
6573

74+
void PreferencesDialog::setDefaultPPI(int ppi)
75+
{
76+
QString ppiStr;
77+
ppiStr.setNum(ppi);
78+
ui->labelDefaultPPI->setText(QString::fromLatin1(": ") + ppiStr);
79+
}
80+
6681
std::vector<std::string> PreferencesDialog::getStdVectorFromEmptyValueList()
6782
{
6883
std::vector<std::string> result;
@@ -228,7 +243,25 @@ void PreferencesDialog::savePreferences()
228243
Settings::setValue(Settings::NUM_DECIMALS, numDecimals);
229244
if (numDecimals != savedNumDecimals)
230245
_tabBar->setFixDecimals(numDecimals);
231-
246+
247+
//PPI
248+
checked = (ui->useDefaultPPI->checkState()==Qt::Checked) ? 1 : 0;
249+
int previousChecked = Settings::value(Settings::PPI_USE_DEFAULT).toInt();
250+
Settings::setValue(Settings::PPI_USE_DEFAULT, checked);
251+
if (checked)
252+
{
253+
if (checked != previousChecked)
254+
_tabBar->useDefaultPPI();
255+
}
256+
else
257+
{
258+
int customPPI = ui->customPPI->text().toInt();
259+
int previousCustomPPI = Settings::value(Settings::PPI_CUSTOM_VALUE).toInt();
260+
Settings::setValue(Settings::PPI_CUSTOM_VALUE, customPPI);
261+
if (checked != previousChecked || customPPI != previousCustomPPI)
262+
_tabBar->setPPI(customPPI);
263+
}
264+
232265
//Done
233266
Settings::sync();
234267

JASP-Desktop/preferencesdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class PreferencesDialog : public QDialog
2020
explicit PreferencesDialog(QWidget *parent = 0);
2121
~PreferencesDialog();
2222

23+
void setDefaultPPI(int ppi);
24+
2325
private:
2426
Ui::PreferencesDialog *ui;
2527
TabBar *_tabBar;

JASP-Desktop/preferencesdialog.ui

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ border-top-right-radius:4px;
151151
<enum>QTabWidget::Rounded</enum>
152152
</property>
153153
<property name="currentIndex">
154-
<number>0</number>
154+
<number>3</number>
155155
</property>
156156
<property name="elideMode">
157157
<enum>Qt::ElideNone</enum>
@@ -160,7 +160,7 @@ border-top-right-radius:4px;
160160
<attribute name="title">
161161
<string>Data Editing</string>
162162
</attribute>
163-
<widget class="QWidget" name="">
163+
<widget class="QWidget" name="layoutWidget">
164164
<property name="geometry">
165165
<rect>
166166
<x>12</x>
@@ -518,6 +518,88 @@ border-top-right-radius:4px;
518518
</item>
519519
</layout>
520520
</widget>
521+
<widget class="QWidget" name="tab_4">
522+
<attribute name="title">
523+
<string>Advanced</string>
524+
</attribute>
525+
<widget class="QWidget" name="verticalLayoutWidget">
526+
<property name="geometry">
527+
<rect>
528+
<x>0</x>
529+
<y>6</y>
530+
<width>278</width>
531+
<height>71</height>
532+
</rect>
533+
</property>
534+
<layout class="QVBoxLayout" name="verticalLayout_4">
535+
<item>
536+
<layout class="QHBoxLayout" name="horizontalLayout_3">
537+
<item>
538+
<widget class="QCheckBox" name="useDefaultPPI">
539+
<property name="text">
540+
<string>Use default PPI (Pixel Per Inch)</string>
541+
</property>
542+
<property name="checked">
543+
<bool>true</bool>
544+
</property>
545+
</widget>
546+
</item>
547+
<item>
548+
<widget class="QLabel" name="labelDefaultPPI">
549+
<property name="text">
550+
<string/>
551+
</property>
552+
</widget>
553+
</item>
554+
</layout>
555+
</item>
556+
<item>
557+
<layout class="QHBoxLayout" name="customPPILayout">
558+
<item>
559+
<spacer name="horizontalSpacer_5">
560+
<property name="orientation">
561+
<enum>Qt::Horizontal</enum>
562+
</property>
563+
<property name="sizeHint" stdset="0">
564+
<size>
565+
<width>40</width>
566+
<height>20</height>
567+
</size>
568+
</property>
569+
</spacer>
570+
</item>
571+
<item>
572+
<widget class="QLabel" name="labelPPI">
573+
<property name="text">
574+
<string>Custom PPI</string>
575+
</property>
576+
</widget>
577+
</item>
578+
<item>
579+
<widget class="QLineEdit" name="customPPI">
580+
<property name="maxLength">
581+
<number>5</number>
582+
</property>
583+
</widget>
584+
</item>
585+
<item>
586+
<spacer name="horizontalSpacer_4">
587+
<property name="orientation">
588+
<enum>Qt::Horizontal</enum>
589+
</property>
590+
<property name="sizeHint" stdset="0">
591+
<size>
592+
<width>40</width>
593+
<height>20</height>
594+
</size>
595+
</property>
596+
</spacer>
597+
</item>
598+
</layout>
599+
</item>
600+
</layout>
601+
</widget>
602+
</widget>
521603
</widget>
522604
</item>
523605
<item>
@@ -558,5 +640,21 @@ border-top-right-radius:4px;
558640
</hint>
559641
</hints>
560642
</connection>
643+
<connection>
644+
<sender>useDefaultPPI</sender>
645+
<signal>toggled(bool)</signal>
646+
<receiver>customPPI</receiver>
647+
<slot>setDisabled(bool)</slot>
648+
<hints>
649+
<hint type="sourcelabel">
650+
<x>126</x>
651+
<y>62</y>
652+
</hint>
653+
<hint type="destinationlabel">
654+
<x>197</x>
655+
<y>102</y>
656+
</hint>
657+
</hints>
658+
</connection>
561659
</connections>
562660
</ui>

JASP-Desktop/resultsjsinterface.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ void ResultsJsInterface::latexCodeSelected()
246246
runJavaScript("window.latexCodeMenuClicked();");
247247
}
248248

249+
void ResultsJsInterface::getDefaultPPI()
250+
{
251+
runJavaScript("window.getPPI()", std::bind(&ResultsJsInterface::cbSetPPIAndRefresh, this, std::placeholders::_1));
252+
}
253+
249254
void ResultsJsInterface::saveImage()
250255
{
251256
runJavaScript("window.saveImageClicked();");
@@ -600,28 +605,35 @@ void ResultsJsInterface::runJavaScript(const QString &str, std::function<void(co
600605
_webViewResults->page()->runJavaScript(str, [cb] (const QVariant &result) { cb(result); });
601606
}
602607

603-
void ResultsJsInterface::cbSetPPI(const QVariant &vppi)
608+
int ResultsJsInterface::_getPPIFromVariant(const QVariant &vppi, bool& success)
604609
{
605-
bool success;
606610
int ppi = vppi.toInt(&success);
607611
if (success == false)
608612
{
609613
std::cout << "Could not get PPI: " << vppi.toString().toStdString() << "." << std::endl;
610614
std::cout.flush();
611615
ppi = 96;
612616
}
613-
else
614-
{
615-
std::cout << "PPI: " << vppi.toString().toStdString() << "." << std::endl;
616-
std::cout.flush();
617617

618-
}
618+
return ppi;
619+
}
619620

621+
void ResultsJsInterface::cbSetPPI(const QVariant &vppi)
622+
{
623+
bool success = false;
624+
int ppi = _getPPIFromVariant(vppi, success);
620625
_webViewZoom = 1;
621626

622627
_mainWindow->resultsPageLoaded(success, ppi);
623628
}
624629

630+
void ResultsJsInterface::cbSetPPIAndRefresh(const QVariant &vppi)
631+
{
632+
bool success = false;
633+
int ppi = _getPPIFromVariant(vppi, success);
634+
_mainWindow->setPPIHandler(ppi);
635+
}
636+
625637
void ResultsJsInterface::cbSetResultstMeta(const QVariant &vMetaData)
626638
{
627639
Json::Reader parser;

JASP-Desktop/resultsjsinterface.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public slots:
8282
void exportSelected(const QString &filename);
8383
void getImageInBase64(int id, const QString &path);
8484
void openFileTab();
85-
85+
86+
void getDefaultPPI();
8687

8788
private:
8889
MainWindow *_mainWindow;
@@ -102,9 +103,12 @@ public slots:
102103
void runJavaScript(const QString &str, std::function<void(const QVariant&)> cb);
103104

104105
void cbSetPPI(const QVariant &vppi);
106+
void cbSetPPIAndRefresh(const QVariant &vppi);
105107
void cbSetResultstMeta(const QVariant &vMetaData);
106108
void cbSetAllUserData(const QVariant &vAllUserData);
107109

110+
int _getPPIFromVariant(const QVariant &vppi, bool &success);
111+
108112
private slots:
109113
void resultsPageLoaded(bool success);
110114
void scrollValueChangedHandle();

JASP-Desktop/settings.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const Settings::Setting Settings::Values[] = {
1515
{"OSFUsername", ""},
1616
{"OSFPassword", ""},
1717
{"OSFEncryption", 0},
18-
{"OSFRememberMe", false}
18+
{"OSFRememberMe", false},
19+
{"PPI_USE_DEFAULT", true},
20+
{"PPI_CUSTOM_VALUE", 96}
1921
};
2022

2123
QVariant Settings::value(Settings::Type key)

JASP-Desktop/settings.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class Settings {
2020
OSF_USERNAME,
2121
OSF_PASSWORD,
2222
OSF_ENCRYPTION,
23-
OSF_REMEMBER_ME
23+
OSF_REMEMBER_ME,
24+
PPI_USE_DEFAULT,
25+
PPI_CUSTOM_VALUE
2426
};
2527

2628
static QVariant value(Settings::Type key);

JASP-Desktop/widgets/tabbar.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ void TabBar::setFixDecimals(QString numDecimals)
334334
emit setFixDecimalsHandler(numDecimals);
335335
}
336336

337+
void TabBar::useDefaultPPI()
338+
{
339+
emit useDefaultPPIHandler();
340+
}
341+
342+
void TabBar::setPPI(int ppi)
343+
{
344+
emit setPPIHandler(ppi);
345+
}
346+
337347

338348
void TabBar::emptyValuesChanged()
339349
{

0 commit comments

Comments
 (0)