aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikko Syrjä <mikko@syrja.org>2019-08-15 21:58:07 +0300
committerMikko Syrjä <mikko@syrja.org>2019-08-15 21:58:07 +0300
commitc557778ab6c7558ff428d49d150b32bc1edc0f32 (patch)
treefe46b1ea7fa89f7164b839c4e6d878e8e2855f70
parentc4f3f55469858998105c5d35e4c905bc4dd59eff (diff)
downloadsymedit-c557778ab6c7558ff428d49d150b32bc1edc0f32.tar.gz
symedit-c557778ab6c7558ff428d49d150b32bc1edc0f32.zip
Fixed inital size and save without file name.
-rw-r--r--main.qml4
-rw-r--r--symedit.cpp40
-rw-r--r--symedit.h4
3 files changed, 36 insertions, 12 deletions
diff --git a/main.qml b/main.qml
index fa90122..b7e4d0b 100644
--- a/main.qml
+++ b/main.qml
@@ -417,10 +417,12 @@ ApplicationWindow
function save(ask)
{
- if ( ask )
+ if ( ask || !manager.hasFilename() )
{
filedialog.fileMode = Labs.FileDialog.SaveFile
filedialog.folder = manager.getTextSetting("Directory")
+// filedialog.file = manager.getFilename()
+ filedialog.currentFile = manager.getFilename()
filedialog.open()
}
else
diff --git a/symedit.cpp b/symedit.cpp
index 6e0b6f5..6c81234 100644
--- a/symedit.cpp
+++ b/symedit.cpp
@@ -1,4 +1,5 @@
#include <QGuiApplication>
+#include <QScreen>
#include <QClipboard>
#include <QSettings>
#include <QDesktopServices>
@@ -36,10 +37,11 @@ void SymEditSettings::Load()
{
QSettings settings;
- Position.setX(settings.value("window/x", 100).toInt());
- Position.setY(settings.value("window/y", 100).toInt());
- Size.setWidth(settings.value("window/width", 500).toInt());
- Size.setHeight(settings.value("window/height", 500).toInt());
+ QSize size = QGuiApplication::primaryScreen()->size();
+ Position.setX(settings.value("window/x", size.width() / 4).toInt());
+ Position.setY(settings.value("window/y", size.height() / 6).toInt());
+ Size.setWidth(settings.value("window/width", size.width() / 2).toInt());
+ Size.setHeight(settings.value("window/height", size.height() * 2 / 3).toInt());
TextValues.at("Directory") = settings.value("application/directory").toString();
@@ -101,12 +103,12 @@ SymEditManager::SymEditManager(QObject* parent) : QObject(parent)
\param symbol Symbol string from command line.
*/
SymEditManager::SymEditManager(const QString& filename, const QString& symbol)
- : QObject(nullptr), FileName(filename)
+ : QObject(nullptr), Filename(filename)
{
Settings.Load();
- if ( !FileName.isEmpty() )
- open(FileName);
+ if ( !Filename.isEmpty() )
+ open(Filename);
if ( !symbol.isEmpty() )
Symbol.Load(symbol);
@@ -573,7 +575,7 @@ bool SymEditManager::open(QUrl fileurl)
*/
bool SymEditManager::save(QUrl fileurl)
{
- QString filename = FileName;
+ QString filename = Filename;
if ( !fileurl.isEmpty() )
{
QString filestring = fileurl.toString();
@@ -585,6 +587,24 @@ bool SymEditManager::save(QUrl fileurl)
return save(filename);
}
+//! Check file name existence.
+/*!
+ \return True for existing file name.
+*/
+bool SymEditManager::hasFilename() const
+{
+ return !Filename.isEmpty();
+}
+
+//! Get file name.
+/*!
+ \return File name as url.
+*/
+QUrl SymEditManager::getFilename() const
+{
+ return QUrl(Filename);
+}
+
//! Open symbol file.
/*!
\param filename Full file path.
@@ -597,7 +617,7 @@ bool SymEditManager::open(const QString& filename)
{
QTextStream input(&file);
Symbol.Load(input.readLine());
- FileName = filename;
+ Filename = filename;
return true;
}
return false;
@@ -615,7 +635,7 @@ bool SymEditManager::save(const QString& filename)
{
QTextStream output(&file);
output << getSymbol(false);
- FileName = filename;
+ Filename = filename;
return true;
}
return false;
diff --git a/symedit.h b/symedit.h
index c850d51..cb4e7b8 100644
--- a/symedit.h
+++ b/symedit.h
@@ -91,6 +91,8 @@ public:
Q_INVOKABLE bool open(QUrl fileurl);
Q_INVOKABLE bool save(QUrl fileurl);
+ Q_INVOKABLE bool hasFilename() const;
+ Q_INVOKABLE QUrl getFilename() const;
bool open(const QString& filename);
bool save(const QString& filename);
@@ -100,7 +102,7 @@ private:
void undosave();
bool Initialized = false; //!< Initialization mutex.
- QString FileName; //!< Symbol file name.
+ QString Filename; //!< Symbol file name.
QString Language; //!< Language id.
SymEditSymbol Symbol; //!< Current symbol.