File: commandlinemanager.cpp

package info (click to toggle)
deepin-shortcut-viewer 5.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 444 kB
  • sloc: cpp: 678; makefile: 7
file content (61 lines) | stat: -rw-r--r-- 2,296 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "commandlinemanager.h"
#include <QFile>
#include <QRect>
#include <QDesktopWidget>
#include <QDebug>
CommandLineManager::CommandLineManager()
    : m_posOption(QStringList() << "p"
                                << "pos",
                  QCoreApplication::translate("main", "Expose your window's central position(x,y) info where the deepin-shorcut-viwer can be center int your window relatively, otherwise it will be center in the current screen. eg: -p=100,50 or --pos=900,50"),
                  " "),
      m_jsonDataOption(QStringList() << "j"
                                     << "json-data",
                       QCoreApplication::translate("main", "Directly convert a json data to this program. See https://github.com/linuxdeepin/deepin-shortcut-viewer or docs provided with the program for more information of this decscription"),
                       " ")
{
    m_commandLineParser.setApplicationDescription("Test helper");
    m_commandLineParser.addHelpOption();
    m_commandLineParser.addVersionOption();
    m_commandLineParser.addOption(m_posOption);
    m_commandLineParser.addOption(m_jsonDataOption);
    m_commandLineParser.addOption(QCommandLineOption(QStringList() << "b"
                                                                   << "bypass",
                                                     "Enable bypass window manager hint"));
}
void CommandLineManager::process(const QCoreApplication &app)
{
    m_commandLineParser.process(app);
}

void CommandLineManager::process(const QStringList &list)
{
    m_commandLineParser.process(list);
}

QString CommandLineManager::jsonData()
{
    return m_commandLineParser.value(m_jsonDataOption);
}

bool CommandLineManager::enableBypassWindowManagerHint() const
{
    return m_commandLineParser.isSet("b");
}

QPoint CommandLineManager::pos()
{
    QString posStr = m_commandLineParser.value(m_posOption);

    QStringList posStrs = posStr.split(",");

    QPoint pos(qApp->desktop()->width() / 2, qApp->desktop()->height() / 2);
    if (posStrs.length() == 2) {
        pos.setX(QString(posStrs[0]).toInt());
        pos.setY(QString(posStrs[1]).toInt());
    }
    return pos;
}