Skip to content

Commit

Permalink
Adjust: parse commandline.
Browse files Browse the repository at this point in the history
Change-Id: Ibb75a5ea25eab53ac06126da8e5b7b9e215d41a7
  • Loading branch information
pangpangpang3 committed Jan 30, 2018
1 parent 76258b9 commit 4eb6cec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
26 changes: 17 additions & 9 deletions frame/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "utils/configsettings.h"
#include "utils/drawfile.h"
#include "utils/tempfile.h"
#include "utils/imageutils.h"
#include "widgets/dialog/drawdialog.h"
#include "../application.h"

Expand Down Expand Up @@ -82,23 +83,30 @@ void MainWindow::loadImage(const QString &path)

void MainWindow::openImage(const QString &path)
{
if (QFileInfo(path).suffix() == "ddf")
if (QFileInfo(path).suffix() == "ddf" && QFileInfo(path).exists())
{
parseDdf(path);
} else {
QSize imageSize = QPixmap(path).size();
QSize desktopSize = qApp->desktop()->size();
int ww = desktopSize.width() - 2*ARTBOARD_MARGIN;
int wh = desktopSize.height() - 2*ARTBOARD_MARGIN - TITLEBAR_HEIGHT;
QSize imageSize = QPixmap(path).size();

if (imageSize.width() > ww || imageSize.height() > wh)
if (QFileInfo(path).exists() && utils::image::imageSupportRead(path)
&& imageSize.width() != 0 && imageSize.height() != 0)
{
resize(desktopSize.width(), desktopSize.height());
int ww = desktopSize.width() - 2*ARTBOARD_MARGIN;
int wh = desktopSize.height() - 2*ARTBOARD_MARGIN - TITLEBAR_HEIGHT;

if (imageSize.width() > ww || imageSize.height() > wh)
{
resize(desktopSize.width(), desktopSize.height());
} else {
emit m_topToolbar->resizeArtboard(true, QSize(imageSize.width(),
imageSize.height() + IMG_ROTATEPOINT_SPACING ));
}
m_mainWidget->openImage(path);
} else {
emit m_topToolbar->resizeArtboard(true, QSize(imageSize.width(),
imageSize.height() + IMG_ROTATEPOINT_SPACING ));
resize(desktopSize.width(), desktopSize.height());
}
m_mainWidget->openImage(path);
}
}

Expand Down
27 changes: 2 additions & 25 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ int main(int argc, char *argv[])
DBusDrawService dbusService(&w);
Q_UNUSED(dbusService);
//Register deepin-draw's dbus service.
// bool dbusServiceExist = false;
QDBusConnection conn = QDBusConnection::sessionBus();
if (!conn.registerService(DEEPIN_DRAW_DBUS_NAME) ||
!conn.registerObject(DEEPIN_DRAW_DBUS_PATH, &w))
{
qDebug() << "deepin-draw is running!";
// dbusServiceExist = true;
}

QCommandLineOption openImageOption(QStringList() << "o" << "open",
Expand All @@ -61,20 +59,10 @@ int main(int argc, char *argv[])
cmdParser.process(a);

if (cmdParser.isSet(openImageOption)) {
// if (dbusServiceExist)
// {
// DBusDraw().openImage(cmdParser.value(openImageOption));
// } else {
w.activeWindow();
w.openImage(cmdParser.value(openImageOption));
// }
} else if (cmdParser.isSet(activeWindowOption)) {
// if (dbusServiceExist)
// {
// DBusDraw().activeWindow();
// } else {
w.activeWindow();
// }
} else {
QStringList pas = cmdParser.positionalArguments();
if (pas.length() >= 1)
Expand All @@ -84,21 +72,10 @@ int main(int argc, char *argv[])
path = QUrl(pas.first()).toLocalFile();
else
path = pas.first();
// if (dbusServiceExist)
// {
// DBusDraw().activeWindow();
// DBusDraw().openImage(QFileInfo(path).absoluteFilePath());
// } else {
w.activeWindow();
w.openImage(QFileInfo(path).absoluteFilePath());
// }
w.activeWindow();
w.openImage(QFileInfo(path).absoluteFilePath());
} else {
// if (dbusServiceExist)
// {
// DBusDraw().activeWindow();
// } else {
w.show();
// }
}
}

Expand Down

0 comments on commit 4eb6cec

Please sign in to comment.