File indexing completed on 2024-04-28 04:32:02

0001 /*
0002  * Copyright (C) 2010-2022 by Stephen Allewell
0003  * steve.allewell@gmail.com
0004  *
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 2 of the License, or
0008  * (at your option) any later version.
0009  */
0010 
0011 /**
0012     @file
0013     Implement the main function that is the first function to be called when the application starts.
0014     Initialises the application and creates any MainWindows required.  Calls exec on the KApplication
0015     to begin the event loop.
0016     */
0017 
0018 /**
0019     @mainpage KXStitch documentation
0020     @section intro_section Introduction
0021     KXStitch is a program that lets you create cross stitch patterns and charts. Patterns can be created
0022     from scratch on a user defined size of grid, which can be enlarged or reduced in size as your pattern
0023     progresses. Alternatively you can import images from many graphics formats or scan images using any
0024     Sane supported scanner. Both of these options allow you to restrict the conversion to full stitches
0025     or optionally use fractional stitches. You may also use an image as a background. These imported images
0026     can then be modified using the supplied tools to produce your final design.
0027 
0028     There are many tools to aid designing your pattern, from open and filled rectangles and ellipses, filled
0029     polygons and lines and backstitching. Additionally cut, copy and paste can be used to duplicate selected
0030     areas. Selected areas can also be rotated 90, 180 and 270 degrees anti clockwise, or mirrored horizontally
0031     or vertically.
0032 
0033     There is also a pattern library that can be used to store small and not so small portions of patterns that
0034     can then be reused in other patterns. The patterns in these library are stored in a hierarchical list that
0035     makes it easy to sort and navigate them to find the ones you want. These pattern libraries can also be used
0036     as alphabets by assigning a character to each one. By using the Alphabet tool, each key press is searched
0037     for in the current library and if present, the associated pattern will be inserted in the pattern.
0038 
0039     When your ready, you can print out your design in several formats. There are options to print out cover
0040     sheets, instructions and a floss key including amount of thread used and number of stitches.
0041 
0042     @section features_section Features
0043     - Creation of new patterns.
0044     - Editing of existing pattern, KXStitch is also capable of reading PC Stitch 5 files.
0045     - Use of various floss pallets, DMC, Anchor, Madeira, JP Coates.
0046     - Creation of custom pallets and colours.
0047     - Use of standard stitches.
0048     - Free use of back stitching.
0049     - Importing of various picture formats.
0050     - Printing of patterns and floss keys.
0051 
0052     @section license_section License
0053     KXStitch is provided as free software; you can redistribute it and/or modify it under the terms of the
0054     GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or
0055     (at your option) any later version.under the GNU General Public License V2
0056     */
0057 
0058 #include <QApplication>
0059 #include <QCommandLineParser>
0060 #include <QUrl>
0061 
0062 #include <KAboutData>
0063 #include <KLocalizedString>
0064 
0065 #include "MainWindow.h"
0066 #include "Version.h"
0067 #include "configuration.h"
0068 
0069 /**
0070     The main function creates an instance of a KAboutData object and populates it with any
0071     information necessary for the application.
0072 
0073     A QApplication object is created to manage the application.  If the session is restored
0074     the previous MainWindows will be restored to their former state when the session was saved.
0075 
0076     Alternatively a QCommandLineParser object is created to manage any arguments passed on the command
0077     line.  For each of the arguments provided, a new MainWindow is created using the arguments url.
0078     This MainWindow is then shown on the desktop.  If no arguments are provided a new MainWindow is
0079     created using an empty QUrl, creating a new document, which is then shown on the desktop.
0080 
0081     The KApplication instance is then executed which begins the event loop allowing user interaction.
0082     */
0083 int main(int argc, char *argv[])
0084 {
0085     QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0086     QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
0087 
0088     QApplication app(argc, argv);
0089     KLocalizedString::setApplicationDomain("kxstitch");
0090 
0091     KAboutData aboutData(QStringLiteral("kxstitch"), // component name
0092                          QString(i18n("kxstitch")), // display name
0093                          QStringLiteral(KXSTITCH_VERSION_STRING), // version
0094                          i18n("A cross stitch pattern creator."), // short description
0095                          KAboutLicense::GPL_V2, // license
0096                          i18n("(c) 2010-2019 Stephen Allewell"), // copyright
0097                          QString(), // other text
0098                          QStringLiteral("http://userbase.kde.org/KXStitch") // home page
0099                          // bug address defaults to submit@bugs.kde.org
0100     );
0101 
0102     aboutData.addAuthor(QStringLiteral("Stephen Allewell"), i18n("Project Lead"), QStringLiteral("steve.allewell@gmail.com"));
0103     aboutData.addCredit(QStringLiteral("Pierre Brua"), i18n("Bug fixes, application icons"), QStringLiteral("kxstitchdev@paralline.com"));
0104     aboutData.addCredit(QStringLiteral("Eric Pareja"), i18n("Man page"), QStringLiteral("xenos@upm.edu.ph"));
0105     aboutData.addCredit(QStringLiteral("Adam Gundy"), i18n("Bug fixes, improvements"), QStringLiteral("adam@starsilk.net"));
0106     aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
0107 
0108     KAboutData::setApplicationData(aboutData);
0109 
0110     app.setApplicationName(aboutData.componentName());
0111     app.setApplicationDisplayName(aboutData.displayName());
0112     app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kxstitch")));
0113     app.setOrganizationDomain(aboutData.organizationDomain());
0114     app.setApplicationVersion(aboutData.version());
0115 
0116     QCommandLineParser parser;
0117     aboutData.setupCommandLine(&parser);
0118     parser.setApplicationDescription(aboutData.shortDescription());
0119 
0120     parser.addPositionalArgument(QStringLiteral("urls"), i18n("Document to open."), QStringLiteral("[urls...]"));
0121 
0122     parser.process(app);
0123 
0124     aboutData.processCommandLine(&parser);
0125 
0126     MainWindow *mainWindow;
0127 
0128     QStringList urls = parser.positionalArguments();
0129 
0130     if (urls.isEmpty()) {
0131         mainWindow = new MainWindow(QUrl());
0132         mainWindow->show();
0133     } else {
0134         foreach (const QString &url, urls) {
0135             mainWindow = new MainWindow(url);
0136             mainWindow->show();
0137         }
0138     }
0139 
0140 #if 0
0141     if (app.isSessionRestored()) {
0142         kRestoreMainWindows<MainWindow>();
0143     } else {
0144         MainWindow *mainWindow;
0145         KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
0146 
0147         if (args->count() > 0) {
0148             for (int i = 0 ; i < args->count() ; ++i) {
0149                 QUrl url = args->url(i);
0150                 mainWindow = new MainWindow(url);
0151                 mainWindow->show();
0152             }
0153         } else {
0154             mainWindow = new MainWindow(QUrl());
0155             mainWindow->show();
0156         }
0157 
0158         args->clear();
0159     }
0160 #endif
0161 
0162     return app.exec();
0163 }