104 lines
3.3 KiB
C++
Raw Normal View History

/***************************************************************************
main.cpp
----------------
begin : Wed Apr 10 2014
copyright : (C) 2014 by Vadim Kuznetsov
email : ra3xdh@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
2014-11-09 11:06:54 +04:00
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <QtCore>
2023-01-26 12:10:45 +03:00
#include <QtWidgets>
#include <QSvgWidget>
#include <QApplication>
#include "qucsactivefilter.h"
struct tQucsSettings QucsSettings;
// #########################################################################
// Loads the settings file and stores the settings.
bool loadSettings()
{
2022-02-18 19:47:32 +01:00
QSettings settings("qucs","qucs_s");
settings.beginGroup("QucsActiveFilter");
if(settings.contains("x"))QucsSettings.x=settings.value("x").toInt();
if(settings.contains("y"))QucsSettings.y=settings.value("y").toInt();
if(settings.contains("showConsole")) QucsSettings.showConsole=settings.value("showConsole").toBool();
settings.endGroup();
if(settings.contains("Language"))QucsSettings.Language=settings.value("Language").toString();
return true;
}
2014-11-09 11:06:54 +04:00
// #########################################################################
// Saves the settings in the settings file.
bool saveApplSettings(QucsActiveFilter *qucs)
{
2022-02-18 19:47:32 +01:00
QSettings settings ("qucs","qucs_s");
settings.beginGroup("QucsActiveFilter");
settings.setValue("x", qucs->x());
settings.setValue("y", qucs->y());
settings.setValue("showConsole", QucsSettings.showConsole);
settings.endGroup();
return true;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString LangDir;
// apply default settings
QucsSettings.x = 200;
QucsSettings.y = 100;
QucsSettings.showConsole = true;
// is application relocated?
QDir QucsDir;
2017-10-20 18:23:21 +03:00
QString QucsApplicationPath = QCoreApplication::applicationDirPath();
#ifdef __APPLE__
2017-10-20 18:23:21 +03:00
QucsDir = QDir(QucsApplicationPath.section("/bin",0,0));
#else
2017-10-20 18:23:21 +03:00
QucsDir = QDir(QucsApplicationPath);
QucsDir.cdUp();
#endif
2017-10-20 18:23:21 +03:00
LangDir = QucsDir.canonicalPath() + "/share/" QUCS_NAME "/lang/";
2014-11-09 11:06:54 +04:00
loadSettings();
2014-11-09 11:06:54 +04:00
QTranslator tor( 0 );
QString Lang = QucsSettings.Language;
2014-11-09 11:06:54 +04:00
if(Lang.isEmpty())
Lang = QString(QLocale::system().name());
static_cast<void>(tor.load( QStringLiteral("qucs_") + Lang, LangDir));
2014-11-09 11:06:54 +04:00
a.installTranslator( &tor );
QucsActiveFilter *w = new QucsActiveFilter();
w->raise();
w->move(QucsSettings.x, QucsSettings.y); // position before "show" !!!
w->show();
int result = a.exec();
saveApplSettings(w);
return result;
}