diff --git a/src/app/puzzle/dialogs/dialogaboutpuzzle.cpp b/src/app/puzzle/dialogs/vpdialogabout.cpp similarity index 89% rename from src/app/puzzle/dialogs/dialogaboutpuzzle.cpp rename to src/app/puzzle/dialogs/vpdialogabout.cpp index 89328bfab..857c0b12e 100644 --- a/src/app/puzzle/dialogs/dialogaboutpuzzle.cpp +++ b/src/app/puzzle/dialogs/vpdialogabout.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file dialogaboutpuzzle.cpp + ** @file vpdialogabout.cpp ** @author Ronan Le Tiec ** @date 11 4, 2020 ** @@ -26,8 +26,8 @@ ** *************************************************************************/ -#include "dialogaboutpuzzle.h" -#include "ui_dialogaboutpuzzle.h" +#include "vpdialogabout.h" +#include "ui_vpdialogabout.h" #include "../version.h" #include "../vmisc/def.h" #include "../fervor/fvupdater.h" @@ -40,9 +40,9 @@ #include //--------------------------------------------------------------------------------------------------------------------- -DialogAboutPuzzle::DialogAboutPuzzle(QWidget *parent) +VPDialogAbout::VPDialogAbout(QWidget *parent) :QDialog(parent), - ui(new Ui::DialogAboutPuzzle), + ui(new Ui::VPDialogAbout), isInitialized(false) { ui->setupUi(this); @@ -57,7 +57,7 @@ DialogAboutPuzzle::DialogAboutPuzzle(QWidget *parent) qWarning() << tr("Cannot open your default browser"); } }); - connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &DialogAboutPuzzle::close); + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &VPDialogAbout::close); connect(ui->pushButtonCheckUpdate, &QPushButton::clicked, []() { // Set feed URL before doing anything else @@ -72,13 +72,13 @@ DialogAboutPuzzle::DialogAboutPuzzle(QWidget *parent) } //--------------------------------------------------------------------------------------------------------------------- -DialogAboutPuzzle::~DialogAboutPuzzle() +VPDialogAbout::~VPDialogAbout() { delete ui; } //--------------------------------------------------------------------------------------------------------------------- -void DialogAboutPuzzle::changeEvent(QEvent *event) +void VPDialogAbout::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { @@ -92,7 +92,7 @@ void DialogAboutPuzzle::changeEvent(QEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void DialogAboutPuzzle::showEvent(QShowEvent *event) +void VPDialogAbout::showEvent(QShowEvent *event) { QDialog::showEvent( event ); if ( event->spontaneous() ) @@ -113,7 +113,7 @@ void DialogAboutPuzzle::showEvent(QShowEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void DialogAboutPuzzle::FontPointSize(QWidget *w, int pointSize) +void VPDialogAbout::FontPointSize(QWidget *w, int pointSize) { SCASSERT(w != nullptr) @@ -123,7 +123,7 @@ void DialogAboutPuzzle::FontPointSize(QWidget *w, int pointSize) } //--------------------------------------------------------------------------------------------------------------------- -void DialogAboutPuzzle::RetranslateUi() +void VPDialogAbout::RetranslateUi() { ui->label_Puzzle_Version->setText(QString("Puzzle %1").arg(APP_VERSION_STR)); ui->labelBuildRevision->setText(tr("Build revision: %1").arg(BUILD_REVISION)); diff --git a/src/app/puzzle/dialogs/dialogaboutpuzzle.h b/src/app/puzzle/dialogs/vpdialogabout.h similarity index 80% rename from src/app/puzzle/dialogs/dialogaboutpuzzle.h rename to src/app/puzzle/dialogs/vpdialogabout.h index 62d0d2498..fce48ca0e 100644 --- a/src/app/puzzle/dialogs/dialogaboutpuzzle.h +++ b/src/app/puzzle/dialogs/vpdialogabout.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file dialogaboutpuzzle.h + ** @file vpdialogabout.h ** @author Ronan Le Tiec ** @date 11 4, 2020 ** @@ -26,31 +26,31 @@ ** *************************************************************************/ -#ifndef DIALOGABOUTPUZZLE_H -#define DIALOGABOUTPUZZLE_H +#ifndef VPDIALOGABOUT_H +#define VPDIALOGABOUT_H #include namespace Ui { - class DialogAboutPuzzle; + class VPDialogAbout; } -class DialogAboutPuzzle : public QDialog +class VPDialogAbout : public QDialog { Q_OBJECT public: - explicit DialogAboutPuzzle(QWidget *parent = nullptr); - virtual ~DialogAboutPuzzle(); + explicit VPDialogAbout(QWidget *parent = nullptr); + virtual ~VPDialogAbout(); protected: virtual void changeEvent(QEvent* event) override; virtual void showEvent(QShowEvent *event) override; private: - Q_DISABLE_COPY(DialogAboutPuzzle) - Ui::DialogAboutPuzzle *ui; + Q_DISABLE_COPY(VPDialogAbout) + Ui::VPDialogAbout *ui; bool isInitialized; void FontPointSize(QWidget *w, int pointSize); @@ -58,4 +58,4 @@ private: void RetranslateUi(); }; -#endif // DIALOGABOUTPUZZLE_H +#endif // VPDIALOGABOUT_H diff --git a/src/app/puzzle/dialogs/dialogaboutpuzzle.ui b/src/app/puzzle/dialogs/vpdialogabout.ui similarity index 98% rename from src/app/puzzle/dialogs/dialogaboutpuzzle.ui rename to src/app/puzzle/dialogs/vpdialogabout.ui index 9b4344117..f98c73aa6 100644 --- a/src/app/puzzle/dialogs/dialogaboutpuzzle.ui +++ b/src/app/puzzle/dialogs/vpdialogabout.ui @@ -1,7 +1,7 @@ - DialogAboutPuzzle - + VPDialogAbout + 0 @@ -296,6 +296,7 @@ + diff --git a/src/app/puzzle/main.cpp b/src/app/puzzle/main.cpp index 86d126b18..16fc44d55 100644 --- a/src/app/puzzle/main.cpp +++ b/src/app/puzzle/main.cpp @@ -29,7 +29,7 @@ #include // For QT_REQUIRE_VERSION #include -#include "puzzleapplication.h" +#include "vpapplication.h" #include "../fervor/fvupdater.h" #include "../vmisc/vsysexits.h" #include "../vmisc/def.h" @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) InitHighDpiScaling(argc, argv); #endif //Q_OS_MAC - PuzzleApplication app(argc, argv); + VPApplication app(argc, argv); app.InitOptions(); if (FvUpdater::IsStaledTestBuild()) @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) return V_EX_UNAVAILABLE; } - QTimer::singleShot(0, &app, &PuzzleApplication::ProcessCMD); + QTimer::singleShot(0, &app, &VPApplication::ProcessCMD); #if defined(APPIMAGE) && defined(Q_OS_LINUX) if (exe_dir) diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index 5ed131c58..5c90f52f5 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -2,54 +2,57 @@ # This need for corect working file translations.pro SOURCES += \ + $$PWD/dialogs/vpdialogabout.cpp \ $$PWD/main.cpp \ - $$PWD/puzzlecommands.cpp \ - $$PWD/puzzlemainwindow.cpp \ - $$PWD/puzzleapplication.cpp \ - $$PWD/vpiececarrouselpiecepreview.cpp \ - $$PWD/vpuzzlecommandline.cpp \ - $$PWD/dialogs/dialogaboutpuzzle.cpp \ - $$PWD/vpiececarrousel.cpp \ - $$PWD/vpuzzlegraphicslayout.cpp \ - $$PWD/vpuzzlegraphicspiece.cpp \ - $$PWD/vpuzzlelayout.cpp \ - $$PWD/vpuzzlelayer.cpp \ - $$PWD/vpuzzlemaingraphicsview.cpp \ - $$PWD/vpuzzlemimedatapiece.cpp \ - $$PWD/vpuzzlepiece.cpp \ - $$PWD/vpuzzlesettings.cpp \ - $$PWD/xml/layoutliterals.cpp \ - $$PWD/xml/vpuzzlelayoutfilewriter.cpp \ - $$PWD/xml/vpuzzlelayoutfilereader.cpp \ - $$PWD/vpiececarrousellayer.cpp \ - $$PWD/vpiececarrouselpiece.cpp + $$PWD/vpapplication.cpp \ + $$PWD/vpcarrousel.cpp \ + $$PWD/vpcarrouselpiece.cpp \ + $$PWD/vpcarrouselpiecelist.cpp \ + $$PWD/vpcommandline.cpp \ + $$PWD/vpcommands.cpp \ + $$PWD/vpgraphicspiece.cpp \ + $$PWD/vpgraphicssheet.cpp \ + $$PWD/vplayout.cpp \ + $$PWD/vpmaingraphicsview.cpp \ + $$PWD/vpmainwindow.cpp \ + $$PWD/vpmimedatapiece.cpp \ + $$PWD/vppiece.cpp \ + $$PWD/vppiecelist.cpp \ + $$PWD/vpsettings.cpp \ + $$PWD/vpsheet.cpp \ + $$PWD/xml/vplayoutfilereader.cpp \ + $$PWD/xml/vplayoutfilewriter.cpp \ + $$PWD/xml/vplayoutliterals.cpp -*msvc*:SOURCES += $$PWD/stable.cpp +*msvc*:SOURCES += HEADERS += \ - $$PWD/puzzlecommands.h \ - $$PWD/puzzlemainwindow.h \ - $$PWD/stable.h \ - $$PWD/puzzleapplication.h \ - $$PWD/vpiececarrouselpiecepreview.h \ - $$PWD/vpuzzlecommandline.h \ - $$PWD/dialogs/dialogaboutpuzzle.h \ - $$PWD/vpiececarrousel.h \ - $$PWD/vpuzzlegraphicslayout.h \ - $$PWD/vpuzzlegraphicspiece.h \ - $$PWD/vpuzzlelayout.h \ - $$PWD/vpuzzlelayer.h \ - $$PWD/vpuzzlemaingraphicsview.h \ - $$PWD/vpuzzlemimedatapiece.h \ - $$PWD/vpuzzlepiece.h \ - $$PWD/vpuzzlesettings.h \ - $$PWD/xml/layoutliterals.h \ - $$PWD/xml/vpuzzlelayoutfilewriter.h \ - $$PWD/xml/vpuzzlelayoutfilereader.h \ - $$PWD/vpiececarrousellayer.h \ - $$PWD/vpiececarrouselpiece.h + $$PWD/dialogs/vpdialogabout.h \ + $$PWD/vpapplication.h \ + $$PWD/vpcarrousel.h \ + $$PWD/vpcarrouselpiece.h \ + $$PWD/vpcarrouselpiecelist.h \ + $$PWD/vpcommandline.h \ + $$PWD/vpcommands.h \ + $$PWD/vpgraphicspiece.h \ + $$PWD/vpgraphicssheet.h \ + $$PWD/vplayout.h \ + $$PWD/vpmaingraphicsview.h \ + $$PWD/vpmainwindow.h \ + $$PWD/vpmimedatapiece.h \ + $$PWD/vppiece.h \ + $$PWD/vppiecelist.h \ + $$PWD/vpsettings.h \ + $$PWD/vpsheet.h \ + $$PWD/vpstable.h \ + $$PWD/xml/vplayoutfilereader.h \ + $$PWD/xml/vplayoutfilewriter.h \ + $$PWD/xml/vplayoutliterals.h FORMS += \ - $$PWD/puzzlemainwindow.ui \ - $$PWD/dialogs/dialogaboutpuzzle.ui \ - $$PWD/vpiececarrousel.ui + $$PWD/dialogs/vpdialogabout.ui \ + $$PWD/vpcarrousel.ui \ + $$PWD/vpmainwindow.ui + +SOURCES += \ + $$PWD/vpstable.cpp diff --git a/src/app/puzzle/puzzleapplication.cpp b/src/app/puzzle/vpapplication.cpp similarity index 91% rename from src/app/puzzle/puzzleapplication.cpp rename to src/app/puzzle/vpapplication.cpp index 32e84e1bd..afd0a559d 100644 --- a/src/app/puzzle/puzzleapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file puzzleapplication.cpp + ** @file vpapplication.cpp ** @author Roman Telezhynskyi ** @date 16 2, 2020 ** @@ -26,9 +26,9 @@ ** *************************************************************************/ -#include "puzzleapplication.h" +#include "vpapplication.h" #include "version.h" -#include "puzzlemainwindow.h" +#include "vpmainwindow.h" #include "../ifc/exception/vexceptionobjecterror.h" #include "../ifc/exception/vexceptionbadid.h" #include "../ifc/exception/vexceptionconversionerror.h" @@ -232,7 +232,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con } //--------------------------------------------------------------------------------------------------------------------- -PuzzleApplication::PuzzleApplication(int &argc, char **argv) +VPApplication::VPApplication(int &argc, char **argv) :VAbstractApplication(argc, argv), mainWindows(), localServer(nullptr) @@ -250,7 +250,7 @@ PuzzleApplication::PuzzleApplication(int &argc, char **argv) } //--------------------------------------------------------------------------------------------------------------------- -PuzzleApplication::~PuzzleApplication() +VPApplication::~VPApplication() { qDeleteAll(mainWindows); } @@ -263,7 +263,7 @@ PuzzleApplication::~PuzzleApplication() * @return value that is returned from the receiver's event handler. */ // reimplemented from QApplication so we can throw exceptions in slots -bool PuzzleApplication::notify(QObject *receiver, QEvent *event) +bool VPApplication::notify(QObject *receiver, QEvent *event) { try { @@ -324,29 +324,29 @@ bool PuzzleApplication::notify(QObject *receiver, QEvent *event) /** * @brief IsAppInGUIMode little hack that allow to have access to application state from VAbstractApplication class. */ -bool PuzzleApplication::IsAppInGUIMode() const +bool VPApplication::IsAppInGUIMode() const { return CommandLine()->IsGuiEnabled(); } //--------------------------------------------------------------------------------------------------------------------- -PuzzleMainWindow *PuzzleApplication::MainWindow() +VPMainWindow *VPApplication::MainWindow() { Clean(); if (mainWindows.isEmpty()) { - VPuzzleCommandLinePtr cmd; - VPuzzleCommandLine::ProcessInstance(cmd, QStringList()); - NewMainWindow(VPuzzleCommandLinePtr()); + VPCommandLinePtr cmd; + VPCommandLine::ProcessInstance(cmd, QStringList()); + NewMainWindow(VPCommandLinePtr()); } return mainWindows[0]; } //--------------------------------------------------------------------------------------------------------------------- -QList PuzzleApplication::MainWindows() +QList VPApplication::MainWindows() { Clean(); - QList list; + QList list; for (auto &w : mainWindows) { list.append(w); @@ -355,9 +355,9 @@ QList PuzzleApplication::MainWindows() } //--------------------------------------------------------------------------------------------------------------------- -PuzzleMainWindow *PuzzleApplication::NewMainWindow(const VPuzzleCommandLinePtr &cmd) +VPMainWindow *VPApplication::NewMainWindow(const VPCommandLinePtr &cmd) { - PuzzleMainWindow *puzzle = new PuzzleMainWindow(cmd); + VPMainWindow *puzzle = new VPMainWindow(cmd); mainWindows.prepend(puzzle); if (cmd->IsGuiEnabled()) { @@ -367,7 +367,7 @@ PuzzleMainWindow *PuzzleApplication::NewMainWindow(const VPuzzleCommandLinePtr & } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::InitOptions() +void VPApplication::InitOptions() { qInstallMessageHandler(noisyFailureMsgHandler); @@ -382,7 +382,7 @@ void PuzzleApplication::InitOptions() LoadTranslation(QLocale().name());// By default the console version uses system locale - VPuzzleCommandLine::Instance(*this); + VPCommandLine::Instance(*this); static const char * GENERIC_ICON_TO_CHECK = "document-open"; if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false) @@ -397,29 +397,29 @@ void PuzzleApplication::InitOptions() } //--------------------------------------------------------------------------------------------------------------------- -const VTranslateVars *PuzzleApplication::TrVars() +const VTranslateVars *VPApplication::TrVars() { return nullptr; } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::OpenSettings() +void VPApplication::OpenSettings() { - settings = new VPuzzleSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), + settings = new VPSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName(), this); } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleSettings *PuzzleApplication::PuzzleSettings() +VPSettings *VPApplication::PuzzleSettings() { SCASSERT(settings != nullptr) - return qobject_cast(settings); + return qobject_cast(settings); } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::ActivateDarkMode() +void VPApplication::ActivateDarkMode() { - VPuzzleSettings *settings = qApp->PuzzleSettings(); + VPSettings *settings = qApp->PuzzleSettings(); if (settings->GetDarkMode()) { QFile f(":qdarkstyle/style.qss"); @@ -437,10 +437,10 @@ void PuzzleApplication::ActivateDarkMode() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, const QStringList &arguments) +void VPApplication::ParseCommandLine(const SocketConnection &connection, const QStringList &arguments) { - VPuzzleCommandLinePtr cmd; - VPuzzleCommandLine::ProcessInstance(cmd, arguments); + VPCommandLinePtr cmd; + VPCommandLine::ProcessInstance(cmd, arguments); if (cmd->IsGuiEnabled() && connection == SocketConnection::Client) { @@ -461,7 +461,7 @@ void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, con qCDebug(mApp, "Can't establish connection to the server '%s'", qUtf8Printable(serverName)); localServer = new QLocalServer(this); - connect(localServer, &QLocalServer::newConnection, this, &PuzzleApplication::NewLocalSocketConnection); + connect(localServer, &QLocalServer::newConnection, this, &VPApplication::NewLocalSocketConnection); if (not localServer->listen(serverName)) { qCDebug(mApp, "Can't begin to listen for incoming connections on name '%s'", @@ -484,7 +484,7 @@ void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, con } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::ProcessArguments(const VPuzzleCommandLinePtr &cmd) +void VPApplication::ProcessArguments(const VPCommandLinePtr &cmd) { const QStringList rawLayouts = cmd->OptionRawLayouts(); const QStringList args = cmd->OptionFileNames(); @@ -545,13 +545,13 @@ void PuzzleApplication::ProcessArguments(const VPuzzleCommandLinePtr &cmd) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::ProcessCMD() +void VPApplication::ProcessCMD() { ParseCommandLine(SocketConnection::Client, arguments()); } //--------------------------------------------------------------------------------------------------------------------- -bool PuzzleApplication::event(QEvent *e) +bool VPApplication::event(QEvent *e) { switch(e->type()) { @@ -563,7 +563,7 @@ bool PuzzleApplication::event(QEvent *e) const QString macFileOpen = fileOpenEvent->file(); if(not macFileOpen.isEmpty()) { - PuzzleMainWindow *mw = MainWindow(); + VPMainWindow *mw = MainWindow(); if (mw) { mw->LoadFile(macFileOpen); // open file in existing window @@ -576,7 +576,7 @@ bool PuzzleApplication::event(QEvent *e) case QEvent::ApplicationActivate: { Clean(); - PuzzleMainWindow *mw = MainWindow(); + VPMainWindow *mw = MainWindow(); if (mw && not mw->isMinimized()) { mw->show(); @@ -591,13 +591,13 @@ bool PuzzleApplication::event(QEvent *e) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::InitTrVars() +void VPApplication::InitTrVars() { // do nothing } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::AboutToQuit() +void VPApplication::AboutToQuit() { // If try to use the method QApplication::exit program can't sync settings and show warning about QApplication // instance. Solution is to call sync() before quit. @@ -606,7 +606,7 @@ void PuzzleApplication::AboutToQuit() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::NewLocalSocketConnection() +void VPApplication::NewLocalSocketConnection() { QScopedPointersocket(localServer->nextPendingConnection()); if (socket.isNull()) @@ -625,7 +625,7 @@ void PuzzleApplication::NewLocalSocketConnection() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleApplication::Clean() +void VPApplication::Clean() { // cleanup any deleted main windows first for (int i = mainWindows.count() - 1; i >= 0; --i) @@ -638,7 +638,7 @@ void PuzzleApplication::Clean() } //-------------------------------------------------------------------------------------------- -VPuzzleCommandLinePtr PuzzleApplication::CommandLine() const +VPCommandLinePtr VPApplication::CommandLine() const { - return VPuzzleCommandLine::instance; + return VPCommandLine::instance; } diff --git a/src/app/puzzle/puzzleapplication.h b/src/app/puzzle/vpapplication.h similarity index 71% rename from src/app/puzzle/puzzleapplication.h rename to src/app/puzzle/vpapplication.h index 0b7b2ac84..bc0ca4b6e 100644 --- a/src/app/puzzle/puzzleapplication.h +++ b/src/app/puzzle/vpapplication.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file puzzleapplication.h + ** @file vpapplication.h ** @author Roman Telezhynskyi ** @date 16 2, 2020 ** @@ -25,52 +25,52 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#ifndef PUZZLEAPPLICATION_H -#define PUZZLEAPPLICATION_H +#ifndef VPAPPLICATION_H +#define VPAPPLICATION_H #include "../vmisc/def.h" -#include "vpuzzlesettings.h" +#include "vpsettings.h" #include "../vmisc/vabstractapplication.h" -#include "vpuzzlecommandline.h" +#include "vpcommandline.h" #include -class PuzzleApplication;// use in define -class PuzzleMainWindow; +class VPApplication;// use in define +class VPMainWindow; class QLocalServer; #if defined(qApp) #undef qApp #endif -#define qApp (static_cast(VAbstractApplication::instance())) +#define qApp (static_cast(VAbstractApplication::instance())) enum class SocketConnection : bool {Client = false, Server = true}; -class PuzzleApplication : public VAbstractApplication +class VPApplication : public VAbstractApplication { Q_OBJECT public: - PuzzleApplication(int &argc, char **argv); - virtual ~PuzzleApplication() override; + VPApplication(int &argc, char **argv); + virtual ~VPApplication() override; virtual bool notify(QObject * receiver, QEvent * event) override; virtual bool IsAppInGUIMode() const override; - PuzzleMainWindow *MainWindow(); - QList MainWindows(); - PuzzleMainWindow *NewMainWindow(const VPuzzleCommandLinePtr &cmd); + VPMainWindow *MainWindow(); + QList MainWindows(); + VPMainWindow *NewMainWindow(const VPCommandLinePtr &cmd); void InitOptions(); virtual const VTranslateVars *TrVars() override; virtual void OpenSettings() override; - VPuzzleSettings *PuzzleSettings(); + VPSettings *PuzzleSettings(); void ActivateDarkMode(); void ParseCommandLine(const SocketConnection &connection, const QStringList &arguments); - void ProcessArguments(const VPuzzleCommandLinePtr &cmd); - VPuzzleCommandLinePtr CommandLine() const; + void ProcessArguments(const VPCommandLinePtr &cmd); + VPCommandLinePtr CommandLine() const; public slots: void ProcessCMD(); @@ -85,11 +85,11 @@ private slots: void NewLocalSocketConnection(); private: - Q_DISABLE_COPY(PuzzleApplication) - QList > mainWindows; + Q_DISABLE_COPY(VPApplication) + QList > mainWindows; QLocalServer *localServer; void Clean(); }; -#endif // PUZZLEAPPLICATION_H +#endif // VPAPPLICATION_H diff --git a/src/app/puzzle/vpiececarrousel.cpp b/src/app/puzzle/vpcarrousel.cpp similarity index 65% rename from src/app/puzzle/vpiececarrousel.cpp rename to src/app/puzzle/vpcarrousel.cpp index 5b0abe3b8..072b3a528 100644 --- a/src/app/puzzle/vpiececarrousel.cpp +++ b/src/app/puzzle/vpcarrousel.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpiececarrousel.cpp + ** @file vpcarrousel.cpp ** @author Ronan Le Tiec ** @date 13 4, 2020 ** @@ -25,14 +25,16 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#include "vpiececarrousel.h" -#include "ui_vpiececarrousel.h" +#include "vpcarrousel.h" +#include "ui_vpcarrousel.h" #include #include #include +#include #include "../vmisc/backport/qoverload.h" -#include "vpuzzlelayer.h" +#include "vppiecelist.h" +#include "vpsheet.h" #include #include @@ -41,95 +43,82 @@ Q_LOGGING_CATEGORY(pCarrousel, "p.carrousel") //--------------------------------------------------------------------------------------------------------------------- -VPieceCarrousel::VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent) : +VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) : QWidget(parent), - ui(new Ui::VPieceCarrousel), + ui(new Ui::VPCarrousel), m_layout(layout) { ui->setupUi(this); + ui->listWidget->SetCarrousel(this); // init the combo box - connect(ui->comboBoxLayer, QOverload::of(&QComboBox::currentIndexChanged), this, - &VPieceCarrousel::on_ActiveLayerChanged); - - ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->comboBoxPieceList, QOverload::of(&QComboBox::currentIndexChanged), this, + &VPCarrousel::on_ActivePieceListChanged); // ------ then we fill the carrousel with the layout content Refresh(); } //--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrousel::Refresh() +void VPCarrousel::Refresh() { - // NOTE: alternative to clearing the carrousel and adding things again, we could make comparision - // --- clears the content of the carrousel Clear(); // --- add the content saved in the layout to the carrousel. // Do not rely on m_layout because we do not control it. - m_layers = m_layout->GetLayers(); - m_layers.prepend(m_layout->GetUnplacedPiecesLayer()); + m_pieceLists = QList(); + m_pieceLists.append(m_layout->GetUnplacedPieceList()); + m_pieceLists.append(m_layout->GetFocusedSheet()->GetPieceList()); - for (auto layer : m_layers) - { - // add layer name to combo - ui->comboBoxLayer->blockSignals(true); - ui->comboBoxLayer->addItem(layer->GetName()); - ui->comboBoxLayer->blockSignals(false); - } + ui->comboBoxPieceList->blockSignals(true); - on_ActiveLayerChanged(0); + ui->comboBoxPieceList->addItem(m_layout->GetUnplacedPieceList()->GetName()); + ui->comboBoxPieceList->addItem(tr("Pieces of ") + m_layout->GetFocusedSheet()->GetName()); + + ui->comboBoxPieceList->blockSignals(false); + + on_ActivePieceListChanged(0); RefreshOrientation(); } //--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrousel::Clear() +void VPCarrousel::Clear() { // remove the combobox entries - ui->comboBoxLayer->clear(); + ui->comboBoxPieceList->clear(); ui->listWidget->clear(); } //--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrousel::on_ActiveLayerChanged(int index) +void VPCarrousel::on_ActivePieceListChanged(int index) { qCDebug(pCarrousel, "index changed %i", index); - ui->listWidget->clear(); - - if (index >= 0 && index < m_layers.size()) + if (index >= 0 && index < m_pieceLists.size()) { - VPuzzleLayer *layer = m_layers.at(index); + VPPieceList *pieceList = m_pieceLists.at(index); - if (layer) - { - QList pieces = layer->GetPieces(); - - for (auto piece : pieces) - { - new QListWidgetItem(piece->PieceIcon(QSize(120, 120)) , piece->GetName(), ui->listWidget); - } - } + ui->listWidget->SetCurrentPieceList(pieceList); } } //--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrousel::SetOrientation(Qt::Orientation orientation) +void VPCarrousel::SetOrientation(Qt::Orientation orientation) { m_orientation = orientation; RefreshOrientation(); } //--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrousel::RefreshOrientation() +void VPCarrousel::RefreshOrientation() { // then update the scrollarea min height / width and scrollbar behaviour if(m_orientation == Qt::Horizontal) { - ui->comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + ui->comboBoxPieceList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); // scroll bar policy of scroll area ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); @@ -139,7 +128,7 @@ void VPieceCarrousel::RefreshOrientation() } else // Qt::Vertical { - ui->comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + ui->comboBoxPieceList->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); // scroll bar policy of scroll area ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); @@ -150,7 +139,17 @@ void VPieceCarrousel::RefreshOrientation() } //--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrousel::ClearSelection() +void VPCarrousel::ClearSelection() { m_layout->ClearSelection(); } + + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrousel::ClearSelectionExceptForCurrentPieceList() +{ + if (m_layout != nullptr) + { + m_layout->ClearSelectionExceptForGivenPieceList(ui->listWidget->GetCurrentPieceList()); + } +} diff --git a/src/app/puzzle/vpiececarrousel.h b/src/app/puzzle/vpcarrousel.h similarity index 72% rename from src/app/puzzle/vpiececarrousel.h rename to src/app/puzzle/vpcarrousel.h index 569ffc3ac..4a3119a0e 100644 --- a/src/app/puzzle/vpiececarrousel.h +++ b/src/app/puzzle/vpcarrousel.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpiececarrousel.h + ** @file vpcarrousel.h ** @author Ronan Le Tiec ** @date 13 04, 2020 ** @@ -26,26 +26,26 @@ ** *************************************************************************/ -#ifndef VPIECECARROUSEL_H -#define VPIECECARROUSEL_H +#ifndef VPCARROUSEL_H +#define VPCARROUSEL_H #include #include #include -#include "vpuzzlelayout.h" -#include "vpuzzlepiece.h" +#include "vplayout.h" +#include "vppiece.h" namespace Ui { -class VPieceCarrousel; +class VPCarrousel; } -class VPieceCarrousel : public QWidget +class VPCarrousel : public QWidget { Q_OBJECT public: - explicit VPieceCarrousel(VPuzzleLayout *layout, QWidget *parent = nullptr); - virtual ~VPieceCarrousel() = default; + explicit VPCarrousel(VPLayout *layout, QWidget *parent = nullptr); + virtual ~VPCarrousel() = default; /** * @brief SetOrientation Sets the orientation to the given value and refreshes @@ -75,12 +75,19 @@ public: */ void ClearSelection(); -private: - Q_DISABLE_COPY(VPieceCarrousel) - Ui::VPieceCarrousel *ui; + /** + * @brief ClearSelectionExceptForCurrentPieceList Clears the selection of all pieces of + * the layout except for the one in the current piece list + */ + void ClearSelectionExceptForCurrentPieceList(); - VPuzzleLayout *m_layout; - QList m_layers{}; +private: + Q_DISABLE_COPY(VPCarrousel) + Ui::VPCarrousel *ui; + + VPLayout *m_layout{nullptr}; + + QList m_pieceLists{}; Qt::Orientation m_orientation{Qt::Vertical}; @@ -88,10 +95,10 @@ private: private slots: /** - * @brief on_ActiveLayerChanged Called when the active layer is changed + * @brief on_ActivePieceListChanged Called when the active piece list is changed * @param index */ - void on_ActiveLayerChanged(int index); + void on_ActivePieceListChanged(int index); }; -#endif // VPIECECARROUSEL_H +#endif // VPCARROUSEL_H diff --git a/src/app/puzzle/vpiececarrousel.ui b/src/app/puzzle/vpcarrousel.ui similarity index 80% rename from src/app/puzzle/vpiececarrousel.ui rename to src/app/puzzle/vpcarrousel.ui index 511853607..32e23095e 100644 --- a/src/app/puzzle/vpiececarrousel.ui +++ b/src/app/puzzle/vpcarrousel.ui @@ -1,7 +1,7 @@ - VPieceCarrousel - + VPCarrousel + 0 @@ -27,7 +27,7 @@ 6 - + 0 @@ -37,12 +37,12 @@ - + Qt::ScrollBarAlwaysOn - QAbstractItemView::DragOnly + QAbstractItemView::NoDragDrop @@ -72,6 +72,13 @@ + + + VPCarrouselPieceList + QListWidget +
vpcarrouselpiecelist.h
+
+
diff --git a/src/app/puzzle/vpcarrouselpiece.cpp b/src/app/puzzle/vpcarrouselpiece.cpp new file mode 100644 index 000000000..93b737238 --- /dev/null +++ b/src/app/puzzle/vpcarrouselpiece.cpp @@ -0,0 +1,122 @@ +/************************************************************************ + ** + ** @file vpcarrouselpiece.cpp + ** @author Ronan Le Tiec + ** @date 25 4, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vpcarrouselpiece.h" + +#include +#include +#include + +#include "vpmimedatapiece.h" +#include "vpcarrouselpiecelist.h" +#include "vpcarrousel.h" +#include "vpsheet.h" + +#include + +Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece") + + +//--------------------------------------------------------------------------------------------------------------------- +VPCarrouselPiece::VPCarrouselPiece(VPPiece *piece, QListWidget* parent) : + QListWidgetItem(parent,1001), + m_piece(piece) +{ + int width = 120 - 8; + QFontMetrics metrix = QFontMetrics(QFont()); + QString clippedText = metrix.elidedText(piece->GetName(), Qt::ElideRight, width); + setIcon(CreatePieceIcon(QSize(120, 120))); + setText(clippedText); +} + + +//--------------------------------------------------------------------------------------------------------------------- +VPCarrouselPiece::~VPCarrouselPiece() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +VPPiece * VPCarrouselPiece::GetPiece() +{ + return m_piece; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPiece::RefreshSelection() +{ + setSelected(m_piece->GetIsSelected()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const +{ + QVector points = m_piece->GetSeamLine(); + if(points.isEmpty()) + { + points = m_piece->GetCuttingLine(); + } + + QPolygonF shape(points); + shape << shape.first(); + + QRectF boundingRect = shape.boundingRect(); + qreal canvasSize = qMax(boundingRect.height(), boundingRect.width()); + QRectF canvas = QRectF(0, 0, canvasSize, canvasSize); + + qreal dx = canvas.center().x() - boundingRect.center().x(); + qreal dy = canvas.center().y() - boundingRect.center().y(); + + QPixmap pixmap(size); + pixmap.fill(QColor("white")); + + QPainter painter; + painter.begin(&pixmap); + painter.setRenderHint(QPainter::Antialiasing); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + + int spacing = 2; + painter.translate(spacing, spacing); + + qreal scaleFactorX = canvasSize * 100 / (size.width() - spacing*2) / 100; + qreal scaleFactorY = canvasSize * 100 / (size.height() - spacing*2) / 100; + painter.scale(1./scaleFactorX, 1./scaleFactorY); + painter.setPen(QPen(Qt::black, 0.8*qMax(scaleFactorX, scaleFactorY))); + + painter.translate(dx, dy); + + painter.drawPolygon(shape); + painter.end(); + + QIcon icon; + + icon.addPixmap(pixmap,QIcon::Normal); + icon.addPixmap(pixmap,QIcon::Selected); + + return icon; +} diff --git a/src/app/puzzle/vpiececarrouselpiecepreview.h b/src/app/puzzle/vpcarrouselpiece.h similarity index 55% rename from src/app/puzzle/vpiececarrouselpiecepreview.h rename to src/app/puzzle/vpcarrouselpiece.h index 9e3049de1..7a2008a7d 100644 --- a/src/app/puzzle/vpiececarrouselpiecepreview.h +++ b/src/app/puzzle/vpcarrouselpiece.h @@ -1,8 +1,8 @@ /************************************************************************ ** - ** @file vpiececarrouselpiecepreview.h + ** @file vpcarrouselpiece.h ** @author Ronan Le Tiec - ** @date 3 5, 2020 + ** @date 25 4, 2020 ** ** @brief ** @copyright @@ -25,21 +25,45 @@ ** along with Valentina. If not, see . ** *************************************************************************/ +#ifndef VPCARROUSELPIECE_H +#define VPCARROUSELPIECE_H -#ifndef VPUZZLEPIECECARROUSELPIECEPREVIEW_H -#define VPUZZLEPIECECARROUSELPIECEPREVIEW_H +#include +#include -#include +#include "vppiece.h" -class VPieceCarrouselPiecePreview: public QGraphicsView + +class VPCarrouselPiece : public QListWidgetItem { public: - VPieceCarrouselPiecePreview(QWidget *parent = nullptr); - ~VPieceCarrouselPiecePreview(); + explicit VPCarrouselPiece(VPPiece *piece, QListWidget* parent); + ~VPCarrouselPiece(); + + /** + * @brief GetPiece Returns the corresponding layout piece + * @return the corresponding layout piece + */ + VPPiece * GetPiece(); + + /** + * @brief RefreshSelection refreshes the selection of the piece according to the selection information of m_piece + */ + void RefreshSelection(); + + /** + * @brief CreatePieceIcon Creates an icon of the piece of given size + * @param size of the icon + * @return the created icon + */ + QIcon CreatePieceIcon(const QSize &size) const; + + +private: + VPPiece *m_piece; + +private slots: -protected: - void mousePressEvent(QMouseEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; }; -#endif // VPUZZLEPIECECARROUSELPIECEPREVIEW_H +#endif // VPCARROUSELPIECE_H diff --git a/src/app/puzzle/vpcarrouselpiecelist.cpp b/src/app/puzzle/vpcarrouselpiecelist.cpp new file mode 100644 index 000000000..c782bfeb7 --- /dev/null +++ b/src/app/puzzle/vpcarrouselpiecelist.cpp @@ -0,0 +1,307 @@ +/************************************************************************ + ** + ** @file vpcarrouselpiecelist.cpp + ** @author Ronan Le Tiec + ** @date 25 4, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#include "vpcarrouselpiecelist.h" + +#include +#include +#include +#include +#include + +#include "vpcarrousel.h" +#include "vpcarrouselpiece.h" +#include "../vmisc/backport/qoverload.h" +#include "vpmimedatapiece.h" + +#include + +Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList") + +//--------------------------------------------------------------------------------------------------------------------- +VPCarrouselPieceList::VPCarrouselPieceList(QWidget* parent) : + QListWidget(parent), + m_dragStart(QPoint()) +{ + setStyleSheet("QListWidget::item{border: 2px solid transparent; color: black;} QListWidget::item:selected {border: 2px solid red;}"); + setContextMenuPolicy(Qt::DefaultContextMenu); + setSelectionMode(QAbstractItemView::MultiSelection); + setViewMode(QListView::IconMode); + + connect(this, &VPCarrouselPieceList::itemSelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedInternal); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPCarrouselPieceList::~VPCarrouselPieceList() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::SetCarrousel(VPCarrousel *carrousel) +{ + m_carrousel = carrousel; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::Refresh() +{ + clear(); + + if(m_pieceList != nullptr) + { + m_pieceList->disconnect(this); + + // Updates the carrousel pieces from the pieces list + QList pieces = m_pieceList->GetPieces(); + + // create the corresponding carrousel pieces + for (auto piece : pieces) + { + // update the label of the piece + VPCarrouselPiece* carrouselpiece = new VPCarrouselPiece(piece,this); + carrouselpiece->setSelected(piece->GetIsSelected()); + connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal); + } + sortItems(); + + connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded); + connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved); + } +} + + +//--------------------------------------------------------------------------------------------------------------------- +VPPieceList* VPCarrouselPieceList::GetCurrentPieceList() +{ + return m_pieceList; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::SetCurrentPieceList(VPPieceList* pieceList) +{ + m_pieceList = pieceList; + + Refresh(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + m_dragStart = event->pos(); + } + + if (!(event->modifiers() & Qt::ControlModifier)) + { + // clearSelection doesn't work properly here so we go through the elements. + for(auto item: selectedItems()) + { + item->setSelected(false); + } + } + + QListWidget::mousePressEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event) +{ + if ((event->buttons() & Qt::LeftButton) && + ((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) && + (selectedItems().count() > 0) && + (m_pieceList->GetSheet() == nullptr)) // only if it's from unplaced pieces + { + startDrag(Qt::MoveAction); + } + else + { + QListWidget::mouseMoveEvent(event); + } +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions) +{ + Q_UNUSED(supportedActions) + + QListWidgetItem* _item = currentItem(); + if(_item->type() == 1001) + { + VPCarrouselPiece *pieceItem = static_cast (_item); + + // starts the dragging + QDrag *drag = new QDrag(this); + VPMimeDataPiece *mimeData = new VPMimeDataPiece(); + VPPiece* piece = pieceItem->GetPiece(); + mimeData->SetPiecePtr(piece); + mimeData->setObjectName("piecePointer"); + + QPixmap pixmap = pieceItem->CreatePieceIcon(QSize(120,120)).pixmap(QSize(120,120)); + + drag->setPixmap(pixmap); + drag->setMimeData(mimeData); + if(drag->exec() == Qt::MoveAction) + { + delete takeItem(row(_item)); + clearSelection(); + piece->SetIsSelected(true); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e) +{ + qCDebug(pCarrouselPieceList, "drag move"); + e->acceptProposedAction(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event) +{ + QListWidgetItem* _item = currentItem(); + if(_item->type() == 1001) + { + VPCarrouselPiece *pieceItem = static_cast (_item); + + QMenu contextMenu; + + if(m_pieceList->GetSheet() == nullptr) + { + VPPieceList* sheetPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetFocusedSheet()->GetPieceList(); + QAction *moveAction = contextMenu.addAction(tr("Move to Sheet")); + QVariant data = QVariant::fromValue(sheetPieces); + moveAction->setData(data); + + connect(moveAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); + } + + // remove from piece list action + if(m_pieceList->GetSheet() != nullptr) + { + VPPieceList* unplacedPieces = pieceItem->GetPiece()->GetPieceList()->GetLayout()->GetUnplacedPieceList(); + QAction *removeAction = contextMenu.addAction(tr("Remove from Sheet")); + QVariant data = QVariant::fromValue(unplacedPieces); + removeAction->setData(data); + connect(removeAction, &QAction::triggered, this, &VPCarrouselPieceList::on_ActionPieceMovedToPieceList); + } + + contextMenu.exec(event->globalPos()); + } +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::on_ActionPieceMovedToPieceList() +{ + QListWidgetItem* _item = currentItem(); + if(_item->type() == 1001) + { + VPCarrouselPiece *pieceItem = static_cast (_item); + QAction *act = qobject_cast(sender()); + QVariant v = act->data(); + VPPieceList *pieceList = v.value(); + if(pieceList != nullptr) + { + pieceList->GetLayout()->MovePieceToPieceList(pieceItem->GetPiece(), pieceList); + } + } +} + + + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece) +{ + if(piece->GetPieceList() == m_pieceList) + { + // update the label of the piece + VPCarrouselPiece* carrouselpiece = new VPCarrouselPiece(piece,this); + carrouselpiece->setSelected(piece->GetIsSelected()); + connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::on_PieceRemoved(VPPiece* piece) +{ + for(int i = 0; i < count(); ++i) + { + QListWidgetItem* _item = item(i); + if(_item->type() == 1001) + { + VPCarrouselPiece *itemPiece = static_cast (_item); + + if(piece == itemPiece->GetPiece()) + { + delete takeItem(row(_item)); + + return; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::on_SelectionChangedInternal() +{ + blockSignals(true); + + for(int i = 0; i < count(); ++i) + { + QListWidgetItem* _item = item(i); + if(_item->type() == 1001) + { + VPCarrouselPiece *itemPiece = static_cast (_item); + itemPiece->GetPiece()->SetIsSelected(itemPiece->isSelected()); + } + } + m_carrousel->ClearSelectionExceptForCurrentPieceList(); + // TODO FIXME: when selecting pieces on the sheet, and then selecting a unplaced piece in the piece carrousel + // the selection is cleared in the sheet (good !) but the cliked item in unplaced pieces in not selected (bad!) + + blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPCarrouselPieceList::on_SelectionChangedExternal() +{ + blockSignals(true); + for(int i = 0; i < count(); ++i) + { + QListWidgetItem* _item = item(i); + if(_item->type() == 1001) + { + VPCarrouselPiece *itemPiece = static_cast (_item); + itemPiece->RefreshSelection(); + } + } + blockSignals(false); +} diff --git a/src/app/puzzle/vpcarrouselpiecelist.h b/src/app/puzzle/vpcarrouselpiecelist.h new file mode 100644 index 000000000..8dd2ee55d --- /dev/null +++ b/src/app/puzzle/vpcarrouselpiecelist.h @@ -0,0 +1,114 @@ +/************************************************************************ + ** + ** @file vpcarrouselpiecelist.h + ** @author Ronan Le Tiec + ** @date 25 4, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPCARROUSELPIECELIST_H +#define VPCARROUSELPIECELIST_H + +#include +#include "vppiecelist.h" +#include "vpcarrousel.h" + + +class VPCarrouselPieceList : public QListWidget +{ + Q_OBJECT +public: + VPCarrouselPieceList(QWidget* parent); + ~VPCarrouselPieceList(); + + /** + * @brief Refresh refreshes the items of the carrousel piece list + */ + void Refresh(); + + /** + * @brief GetPieceList Returns the corresponding VPPieceList + * @return the VPPieceList + */ + VPPieceList* GetCurrentPieceList(); + + /** + * @brief SetCurrentPieceList Sets the current piece list to the given piece list and redraw + * the carrousel. + */ + void SetCurrentPieceList(VPPieceList *pieceList); + + /** + * @brief SetCarrousel Sets the carrousel corresponding to the list + * @param carrousel + */ + void SetCarrousel(VPCarrousel *carrousel); + + +public slots: + /** + * @brief on_SelectionChangedExternal when the selection was changed outside of the carrousel + */ + void on_SelectionChangedExternal(); + +protected: + void startDrag(Qt::DropActions supportedActions) override; + void dragMoveEvent(QDragMoveEvent* e) override; + + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + + void contextMenuEvent(QContextMenuEvent *event) override; + +private: + Q_DISABLE_COPY(VPCarrouselPieceList) + + VPPieceList *m_pieceList{nullptr}; + QPoint m_dragStart; + VPCarrousel *m_carrousel{nullptr}; + +private slots: + + /** + * @brief on_PieceUpdated This slot is called when a piece was added + */ + void on_PieceAdded(VPPiece* piece); + + /** + * @brief on_PieceUpdated This slot is called when a piece was removed + */ + void on_PieceRemoved(VPPiece* piece); + + /** + * @brief on_SelectionChangedInternal when the selection was changed inside of the carrousel + */ + void on_SelectionChangedInternal(); + + /** + * @brief on_ActionPieceMovedToPieceList when a piece is moved to another piece list via a context menu + */ + void on_ActionPieceMovedToPieceList(); + +}; + +#endif // VPCARROUSELPIECELIST_H diff --git a/src/app/puzzle/vpuzzlecommandline.cpp b/src/app/puzzle/vpcommandline.cpp similarity index 86% rename from src/app/puzzle/vpuzzlecommandline.cpp rename to src/app/puzzle/vpcommandline.cpp index bc08399eb..ca94b76d1 100644 --- a/src/app/puzzle/vpuzzlecommandline.cpp +++ b/src/app/puzzle/vpcommandline.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlecommandline.cpp + ** @file vpcommandline.cpp ** @author Roman Telezhynskyi ** @date 12 4, 2020 ** @@ -25,31 +25,31 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#include "vpuzzlecommandline.h" -#include "puzzlecommands.h" +#include "vpcommandline.h" +#include "vpcommands.h" #include "../vmisc/vsysexits.h" #include "../vmisc/literals.h" #include -std::shared_ptr VPuzzleCommandLine::instance = nullptr; +std::shared_ptr VPCommandLine::instance = nullptr; #define translate(context, source) QCoreApplication::translate((context), source) //------------------------------------------------------------------------------------------------ -bool VPuzzleCommandLine::IsExportEnabled() const +bool VPCommandLine::IsExportEnabled() const { const bool result = IsOptionSet(LONG_OPTION_EXPORT_FILE); int argSize = parser.positionalArguments().size(); if (result && argSize != 1) { qCritical() << translate("Puzzle", "Export options can be used with single input file only.") << "/n"; - const_cast(this)->parser.showHelp(V_EX_USAGE); + const_cast(this)->parser.showHelp(V_EX_USAGE); } return result; } //---------------------------------------------------------------------------------------------- -QString VPuzzleCommandLine::OptionExportFile() const +QString VPCommandLine::OptionExportFile() const { QString path; if (IsExportEnabled()) @@ -61,49 +61,49 @@ QString VPuzzleCommandLine::OptionExportFile() const } //--------------------------------------------------------------------------------------------------------------------- -QStringList VPuzzleCommandLine::OptionRawLayouts() const +QStringList VPCommandLine::OptionRawLayouts() const { return OptionValues(LONG_OPTION_RAW_LAYOUT); } //-------------------------------------------------------------------------------------------- -bool VPuzzleCommandLine::IsTestModeEnabled() const +bool VPCommandLine::IsTestModeEnabled() const { const bool r = IsOptionSet(LONG_OPTION_TEST); if (r && parser.positionalArguments().size() != 1) { qCritical() << translate("VCommandLine", "Test option can be used with single input file only.") << "/n"; - const_cast(this)->parser.showHelp(V_EX_USAGE); + const_cast(this)->parser.showHelp(V_EX_USAGE); } return r; } //-------------------------------------------------------------------------------------------- -bool VPuzzleCommandLine::IsGuiEnabled() const +bool VPCommandLine::IsGuiEnabled() const { return isGuiEnabled; } //-------------------------------------------------------------------------------------------- -QStringList VPuzzleCommandLine::OptionFileNames() const +QStringList VPCommandLine::OptionFileNames() const { return parser.positionalArguments(); } //------------------------------------------------------------------------------------------- -bool VPuzzleCommandLine::IsNoScalingEnabled() const +bool VPCommandLine::IsNoScalingEnabled() const { return IsOptionSet(LONG_OPTION_NO_HDPI_SCALING); } //---------------------------------------------------------------------------------------------------------------------- -void VPuzzleCommandLine::ShowHelp(int exitCode) +void VPCommandLine::ShowHelp(int exitCode) { parser.showHelp(exitCode); } //---------------------------------------------------------------------------------------------- -VPuzzleCommandLine::VPuzzleCommandLine(): +VPCommandLine::VPCommandLine(): parser(), isGuiEnabled(false) { @@ -116,18 +116,18 @@ VPuzzleCommandLine::VPuzzleCommandLine(): } //------------------------------------------------------------------------------------------- -VPuzzleCommandLinePtr VPuzzleCommandLine::Instance(const QCoreApplication &app) +VPCommandLinePtr VPCommandLine::Instance(const QCoreApplication &app) { - VPuzzleCommandLine::ProcessInstance(instance, app.arguments()); + VPCommandLine::ProcessInstance(instance, app.arguments()); return instance; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleCommandLine::ProcessInstance(VPuzzleCommandLinePtr &instance, const QStringList &arguments) +void VPCommandLine::ProcessInstance(VPCommandLinePtr &instance, const QStringList &arguments) { if (instance == nullptr) { - instance.reset(new VPuzzleCommandLine); + instance.reset(new VPCommandLine); } instance->parser.process(arguments); @@ -135,7 +135,7 @@ void VPuzzleCommandLine::ProcessInstance(VPuzzleCommandLinePtr &instance, const } //------------------------------------------------------------------------------------------- -void VPuzzleCommandLine::InitCommandLineOptions() +void VPCommandLine::InitCommandLineOptions() { //keep in mind order here - that is how user will see it, so group-up for usability //================================================================================================================= @@ -193,19 +193,19 @@ void VPuzzleCommandLine::InitCommandLineOptions() } //-------------------------------------------------------------------------------------------- -bool VPuzzleCommandLine::IsOptionSet(const QString &option) const +bool VPCommandLine::IsOptionSet(const QString &option) const { return parser.isSet(option); } //------------------------------------------------------------------------------------------- -QString VPuzzleCommandLine::OptionValue(const QString &option) const +QString VPCommandLine::OptionValue(const QString &option) const { return parser.value(option); } //-------------------------------------------------------------------------------------------- -QStringList VPuzzleCommandLine::OptionValues(const QString &option) const +QStringList VPCommandLine::OptionValues(const QString &option) const { return parser.values(option); } diff --git a/src/app/puzzle/vpuzzlecommandline.h b/src/app/puzzle/vpcommandline.h similarity index 77% rename from src/app/puzzle/vpuzzlecommandline.h rename to src/app/puzzle/vpcommandline.h index 0bd64c8e2..5cc1f3444 100644 --- a/src/app/puzzle/vpuzzlecommandline.h +++ b/src/app/puzzle/vpcommandline.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlecommandline.h + ** @file vpcommandline.h ** @author Dmytro Hladkykh ** @date 12 4, 2020 ** @@ -25,21 +25,21 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#ifndef VPUZZLECOMMANDLINE_H -#define VPUZZLECOMMANDLINE_H +#ifndef VPCOMMANDLINE_H +#define VPCOMMANDLINE_H #include #include #include -class VPuzzleCommandLine; -using VPuzzleCommandLinePtr = std::shared_ptr; +class VPCommandLine; +using VPCommandLinePtr = std::shared_ptr; -class VPuzzleCommandLine: public QObject +class VPCommandLine: public QObject { Q_OBJECT public: - virtual ~VPuzzleCommandLine() = default; + virtual ~VPCommandLine() = default; /** @brief if user enabled export from cmd */ bool IsExportEnabled() const; @@ -64,17 +64,17 @@ public: Q_NORETURN void ShowHelp(int exitCode = 0); protected: - VPuzzleCommandLine(); + VPCommandLine(); - /** @brief create the single instance of the class inside puzzleapplication */ - static VPuzzleCommandLinePtr Instance(const QCoreApplication &app); - static void ProcessInstance(VPuzzleCommandLinePtr &instance, const QStringList &arguments); + /** @brief create the single instance of the class inside vpapplication */ + static VPCommandLinePtr Instance(const QCoreApplication &app); + static void ProcessInstance(VPCommandLinePtr &instance, const QStringList &arguments); private: - Q_DISABLE_COPY(VPuzzleCommandLine) - static VPuzzleCommandLinePtr instance; + Q_DISABLE_COPY(VPCommandLine) + static VPCommandLinePtr instance; QCommandLineParser parser; bool isGuiEnabled; - friend class PuzzleApplication; + friend class VPApplication; /** @brief add options to the QCommandLineParser that there are in the cmd can be */ void InitCommandLineOptions(); @@ -84,4 +84,4 @@ private: QStringList OptionValues(const QString &option) const; }; -#endif // VPUZZLECOMMANDLINE_H +#endif // VPCOMMANDLINE_H diff --git a/src/app/puzzle/puzzlecommands.cpp b/src/app/puzzle/vpcommands.cpp similarity index 98% rename from src/app/puzzle/puzzlecommands.cpp rename to src/app/puzzle/vpcommands.cpp index 57134ad2d..b10c0d1d3 100644 --- a/src/app/puzzle/puzzlecommands.cpp +++ b/src/app/puzzle/vpcommands.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file commands.cpp + ** @file vpcommands.cpp ** @author Roman Telezhynskyi ** @date 13 4, 2020 ** @@ -25,7 +25,7 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#include "puzzlecommands.h" +#include "vpcommands.h" #include diff --git a/src/app/puzzle/puzzlecommands.h b/src/app/puzzle/vpcommands.h similarity index 95% rename from src/app/puzzle/puzzlecommands.h rename to src/app/puzzle/vpcommands.h index ae362b032..4db42b939 100644 --- a/src/app/puzzle/puzzlecommands.h +++ b/src/app/puzzle/vpcommands.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file commands.h + ** @file vpcommands.h ** @author Roman Telezhynskyi ** @date 13 4, 2020 ** @@ -25,8 +25,8 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#ifndef COMMANDS_H -#define COMMANDS_H +#ifndef VPCOMMANDS_H +#define VPCOMMANDS_H #include @@ -60,4 +60,4 @@ extern const QString LONG_OPTION_TILED_PDF_LANDSCAPE; QStringList AllKeys(); -#endif // COMMANDS_H +#endif // VPCOMMANDS_H diff --git a/src/app/puzzle/vpuzzlegraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp similarity index 74% rename from src/app/puzzle/vpuzzlegraphicspiece.cpp rename to src/app/puzzle/vpgraphicspiece.cpp index 3d53423fe..4bf150701 100644 --- a/src/app/puzzle/vpuzzlegraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlegraphicspiece.cpp + ** @file vpgraphicspiece.cpp ** @author Ronan Le Tiec ** @date 4 5, 2020 ** @@ -26,7 +26,7 @@ ** *************************************************************************/ -#include "vpuzzlegraphicspiece.h" +#include "vpgraphicspiece.h" #include #include @@ -39,15 +39,16 @@ #include #include -#include "vpuzzlepiece.h" -#include "vpuzzlelayer.h" -#include "vpuzzlelayout.h" +#include "vppiece.h" +#include "vppiecelist.h" +#include "vplayout.h" +#include "vpsheet.h" #include Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece") //--------------------------------------------------------------------------------------------------------------------- -VPuzzleGraphicsPiece::VPuzzleGraphicsPiece(VPuzzlePiece *piece, QGraphicsItem *parent) : +VPGraphicsPiece::VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent) : QGraphicsObject(parent), m_piece(piece), m_cuttingLine(QPainterPath()), @@ -59,13 +60,13 @@ VPuzzleGraphicsPiece::VPuzzleGraphicsPiece(VPuzzlePiece *piece, QGraphicsItem *p } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleGraphicsPiece::~VPuzzleGraphicsPiece() +VPGraphicsPiece::~VPGraphicsPiece() { } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::Init() +void VPGraphicsPiece::Init() { // set some infos setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); @@ -74,39 +75,47 @@ void VPuzzleGraphicsPiece::Init() // initialises the seam line QVector seamLinePoints = m_piece->GetSeamLine(); - m_seamLine.moveTo(seamLinePoints.first()); - for (int i = 1; i < seamLinePoints.size(); ++i) - m_seamLine.lineTo(seamLinePoints.at(i)); + if(!seamLinePoints.isEmpty()) + { + m_seamLine.moveTo(seamLinePoints.first()); + for (int i = 1; i < seamLinePoints.size(); ++i) + m_seamLine.lineTo(seamLinePoints.at(i)); + } // initiliases the cutting line QVector cuttingLinepoints = m_piece->GetCuttingLine(); - m_cuttingLine.moveTo(cuttingLinepoints.first()); - for (int i = 1; i < cuttingLinepoints.size(); ++i) - m_cuttingLine.lineTo(cuttingLinepoints.at(i)); + if(!cuttingLinepoints.isEmpty()) + { + m_cuttingLine.moveTo(cuttingLinepoints.first()); + for (int i = 1; i < cuttingLinepoints.size(); ++i) + m_cuttingLine.lineTo(cuttingLinepoints.at(i)); + } // initialises the grainline QVector grainLinepoints = m_piece->GetGrainline(); - m_grainline.moveTo(grainLinepoints.first()); - for (int i = 1; i < grainLinepoints.size(); ++i) - m_grainline.lineTo(grainLinepoints.at(i)); - + if(!grainLinepoints.isEmpty()) + { + m_grainline.moveTo(grainLinepoints.first()); + for (int i = 1; i < grainLinepoints.size(); ++i) + m_grainline.lineTo(grainLinepoints.at(i)); + } // TODO : initialises the other elements labels, passmarks etc. // Initialises the connectors - connect(m_piece, &VPuzzlePiece::SelectionChanged, this, &VPuzzleGraphicsPiece::on_PieceSelectionChanged); - connect(m_piece, &VPuzzlePiece::PositionChanged, this, &VPuzzleGraphicsPiece::on_PiecePositionChanged); - connect(m_piece, &VPuzzlePiece::RotationChanged, this, &VPuzzleGraphicsPiece::on_PieceRotationChanged); + connect(m_piece, &VPPiece::SelectionChanged, this, &VPGraphicsPiece::on_PieceSelectionChanged); + connect(m_piece, &VPPiece::PositionChanged, this, &VPGraphicsPiece::on_PiecePositionChanged); + connect(m_piece, &VPPiece::RotationChanged, this, &VPGraphicsPiece::on_PieceRotationChanged); } //--------------------------------------------------------------------------------------------------------------------- -VPuzzlePiece* VPuzzleGraphicsPiece::GetPiece() +VPPiece* VPGraphicsPiece::GetPiece() { return m_piece; } //--------------------------------------------------------------------------------------------------------------------- -QRectF VPuzzleGraphicsPiece::boundingRect() const +QRectF VPGraphicsPiece::boundingRect() const { if(!m_cuttingLine.isEmpty()) { @@ -117,7 +126,7 @@ QRectF VPuzzleGraphicsPiece::boundingRect() const } //--------------------------------------------------------------------------------------------------------------------- -QPainterPath VPuzzleGraphicsPiece::shape() const +QPainterPath VPGraphicsPiece::shape() const { if(!m_cuttingLine.isEmpty()) { @@ -128,7 +137,7 @@ QPainterPath VPuzzleGraphicsPiece::shape() const } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); Q_UNUSED(option); @@ -171,7 +180,7 @@ void VPuzzleGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsIt } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event) +void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event) { bool selectionState = isSelected(); //perform the default behaviour @@ -206,7 +215,7 @@ void VPuzzleGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::mouseMoveEvent(QGraphicsSceneMouseEvent * event) +void VPGraphicsPiece::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { if((event->buttons() == Qt::LeftButton) && (event->modifiers() & Qt::AltModifier)) { @@ -237,7 +246,7 @@ void VPuzzleGraphicsPiece::mouseMoveEvent(QGraphicsSceneMouseEvent * event) //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void VPGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { bool selectionState = isSelected(); @@ -264,7 +273,7 @@ void VPuzzleGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +void VPGraphicsPiece::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { if(event->modifiers() & Qt::AltModifier) @@ -284,73 +293,82 @@ void VPuzzleGraphicsPiece::hoverMoveEvent(QGraphicsSceneHoverEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { + + + // TODO/FIXME context menu needs to be refactored + QMenu contextMenu; - // move to layer actions -- TODO : To be tested properly when we have several layers - QList layers = m_piece->GetLayer()->GetLayout()->GetLayers(); - layers.removeAll(m_piece->GetLayer()); + // move to piece list actions -- TODO : To be tested properly when we have several piece lists + QList pieceLists = QList(); + for(auto sheet : m_piece->GetPieceList()->GetLayout()->GetSheets()) + { + pieceLists.append(sheet->GetPieceList()); + } - if(layers.count() > 0) + pieceLists.removeAll(m_piece->GetPieceList()); + + if(pieceLists.count() > 0) { QMenu *moveMenu = contextMenu.addMenu(tr("Move to")); // TODO order in alphabetical order - for (auto layer : layers) + for (auto pieceList : pieceLists) { - QAction* moveToLayer = moveMenu->addAction(layer->GetName()); - QVariant data = QVariant::fromValue(layer); - moveToLayer->setData(data); + QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName()); + QVariant data = QVariant::fromValue(pieceList); + moveToPieceList->setData(data); - connect(moveToLayer, &QAction::triggered, this, &VPuzzleGraphicsPiece::on_ActionPieceMovedToLayer); + connect(moveToPieceList, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList); } } // remove from layout action - QAction *removeAction = contextMenu.addAction(tr("Remove from Layout")); - QVariant data = QVariant::fromValue(m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer()); + QAction *removeAction = contextMenu.addAction(tr("Remove from Sheet")); + QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList()); removeAction->setData(data); - connect(removeAction, &QAction::triggered, this, &VPuzzleGraphicsPiece::on_ActionPieceMovedToLayer); + connect(removeAction, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList); contextMenu.exec(event->screenPos()); } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::on_ActionPieceMovedToLayer() +void VPGraphicsPiece::on_ActionPieceMovedToPieceList() { QAction *act = qobject_cast(sender()); QVariant v = act->data(); - VPuzzleLayer *layer = v.value(); - if(layer != nullptr) + VPPieceList *pieceList = v.value(); + if(pieceList != nullptr) { - layer->GetLayout()->MovePieceToLayer(m_piece, layer); + pieceList->GetLayout()->MovePieceToPieceList(m_piece, pieceList); } } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::on_PieceSelectionChanged() +void VPGraphicsPiece::on_PieceSelectionChanged() { setSelected(m_piece->GetIsSelected()); } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::on_PiecePositionChanged() +void VPGraphicsPiece::on_PiecePositionChanged() { setPos(m_piece->GetPosition()); } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsPiece::on_PieceRotationChanged() +void VPGraphicsPiece::on_PieceRotationChanged() { setTransformOriginPoint(boundingRect().center()); setRotation(-m_piece->GetRotation()); } //--------------------------------------------------------------------------------------------------------------------- -QVariant VPuzzleGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &value) +QVariant VPGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &value) { if (scene()) { diff --git a/src/app/puzzle/vpuzzlegraphicspiece.h b/src/app/puzzle/vpgraphicspiece.h similarity index 81% rename from src/app/puzzle/vpuzzlegraphicspiece.h rename to src/app/puzzle/vpgraphicspiece.h index fee04892f..66f49f401 100644 --- a/src/app/puzzle/vpuzzlegraphicspiece.h +++ b/src/app/puzzle/vpgraphicspiece.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlegraphicspiece.h + ** @file vpgraphicspiece.h ** @author Ronan Le Tiec ** @date 4 5, 2020 ** @@ -26,26 +26,26 @@ ** *************************************************************************/ -#ifndef VPUZZLEGRAPHICSPIECE_H -#define VPUZZLEGRAPHICSPIECE_H +#ifndef VPGRAPHICSPIECE_H +#define VPGRAPHICSPIECE_H #include -class VPuzzlePiece; +class VPPiece; -class VPuzzleGraphicsPiece : public QGraphicsObject +class VPGraphicsPiece : public QGraphicsObject { Q_OBJECT public: - VPuzzleGraphicsPiece(VPuzzlePiece *piece, QGraphicsItem *parent = nullptr); - ~VPuzzleGraphicsPiece(); + VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent = nullptr); + ~VPGraphicsPiece(); void Init(); /** * @brief GetPiece Returns the piece that corresponds to the graphics piece * @return the piece */ - VPuzzlePiece* GetPiece(); + VPPiece* GetPiece(); public slots: /** @@ -80,14 +80,14 @@ protected: private slots: /** - * @brief on_ActionPieceMovedToLayer Slot called when the piece is moved via the - * context menu to anoter layer + * @brief on_ActionPieceMovedToPieceList Slot called when the piece is moved via the + * context menu to anoter piece list */ - void on_ActionPieceMovedToLayer(); + void on_ActionPieceMovedToPieceList(); private: - Q_DISABLE_COPY(VPuzzleGraphicsPiece) - VPuzzlePiece *m_piece; + Q_DISABLE_COPY(VPGraphicsPiece) + VPPiece *m_piece; QPainterPath m_cuttingLine; QPainterPath m_seamLine; @@ -97,4 +97,4 @@ private: }; -#endif // VPUZZLEGRAPHICSPIECE_H +#endif // VPGRAPHICSPIECE_H diff --git a/src/app/puzzle/vpuzzlegraphicslayout.cpp b/src/app/puzzle/vpgraphicssheet.cpp similarity index 76% rename from src/app/puzzle/vpuzzlegraphicslayout.cpp rename to src/app/puzzle/vpgraphicssheet.cpp index 00185b9b5..77b496a4c 100644 --- a/src/app/puzzle/vpuzzlegraphicslayout.cpp +++ b/src/app/puzzle/vpgraphicssheet.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlegraphicslayout.cpp + ** @file vpgraphicssheet.cpp ** @author Ronan Le Tiec ** @date 3 5, 2020 ** @@ -26,25 +26,25 @@ ** *************************************************************************/ -#include "vpuzzlegraphicslayout.h" +#include "vpgraphicssheet.h" //--------------------------------------------------------------------------------------------------------------------- -VPuzzleGraphicsLayout::VPuzzleGraphicsLayout(VPuzzleLayout *layout, QGraphicsItem *parent): +VPGraphicsSheet::VPGraphicsSheet(VPSheet *sheet, QGraphicsItem *parent): QGraphicsItem(parent), - m_layout(layout), - m_boundingRect(GetLayoutRect()) + m_sheet(sheet), + m_boundingRect(GetSheetRect()) { } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleGraphicsLayout::~VPuzzleGraphicsLayout() +VPGraphicsSheet::~VPGraphicsSheet() { } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleGraphicsLayout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); Q_UNUSED(option); @@ -60,23 +60,23 @@ void VPuzzleGraphicsLayout::paint(QPainter *painter, const QStyleOptionGraphicsI pen.setColor(Qt::black); painter->setPen(pen); - painter->drawRect(GetLayoutRect()); + painter->drawRect(GetSheetRect()); - m_boundingRect = GetLayoutRect(); + m_boundingRect = GetSheetRect(); } //--------------------------------------------------------------------------------------------------------------------- -QRectF VPuzzleGraphicsLayout::GetLayoutRect() const +QRectF VPGraphicsSheet::GetSheetRect() const { - QRectF rect = QRectF(QPointF(0,0), m_layout->GetLayoutSize()); + QRectF rect = QRectF(QPointF(0,0), m_sheet->GetSheetSize()); return rect; } //--------------------------------------------------------------------------------------------------------------------- -QRectF VPuzzleGraphicsLayout::GetMarginsRect() const +QRectF VPGraphicsSheet::GetMarginsRect() const { - QMarginsF margins = m_layout->GetLayoutMargins(); - QSizeF size = m_layout->GetLayoutSize(); + QMarginsF margins = m_sheet->GetSheetMargins(); + QSizeF size = m_sheet->GetSheetSize(); QRectF rect = QRectF( QPointF(margins.left(),margins.top()), QPointF(size.width()-margins.right(), size.height()-margins.bottom()) @@ -86,7 +86,7 @@ QRectF VPuzzleGraphicsLayout::GetMarginsRect() const //--------------------------------------------------------------------------------------------------------------------- -QRectF VPuzzleGraphicsLayout::boundingRect() const +QRectF VPGraphicsSheet::boundingRect() const { return m_boundingRect; } diff --git a/src/app/puzzle/vpuzzlegraphicslayout.h b/src/app/puzzle/vpgraphicssheet.h similarity index 76% rename from src/app/puzzle/vpuzzlegraphicslayout.h rename to src/app/puzzle/vpgraphicssheet.h index a8c2c509e..0c20ea2ec 100644 --- a/src/app/puzzle/vpuzzlegraphicslayout.h +++ b/src/app/puzzle/vpgraphicssheet.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlegraphicslayout.h + ** @file vpgraphicssheet.h ** @author Ronan Le Tiec ** @date 3 5, 2020 ** @@ -26,33 +26,33 @@ ** *************************************************************************/ -#ifndef VPUZZLEGRAPHICSLAYOUT_H -#define VPUZZLEGRAPHICSLAYOUT_H +#ifndef VPGRAPHICSSHEET_H +#define VPGRAPHICSSHEET_H #include #include -#include "vpuzzlelayout.h" +#include "vpsheet.h" -class VPuzzleGraphicsLayout : public QGraphicsItem +class VPGraphicsSheet : public QGraphicsItem { public: - explicit VPuzzleGraphicsLayout(VPuzzleLayout *layout, QGraphicsItem *parent = nullptr); - ~VPuzzleGraphicsLayout(); + explicit VPGraphicsSheet(VPSheet *sheet, QGraphicsItem *parent = nullptr); + ~VPGraphicsSheet(); QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) override; - QRectF GetLayoutRect() const; + QRectF GetSheetRect() const; QRectF GetMarginsRect() const; private: - Q_DISABLE_COPY(VPuzzleGraphicsLayout) + Q_DISABLE_COPY(VPGraphicsSheet) - VPuzzleLayout *m_layout{nullptr}; + VPSheet *m_sheet{nullptr}; QRectF m_boundingRect; }; -#endif // VPUZZLEGRAPHICSLAYOUT_H +#endif // VPGRAPHICSSHEET_H diff --git a/src/app/puzzle/vpiececarrousellayer.cpp b/src/app/puzzle/vpiececarrousellayer.cpp deleted file mode 100644 index b784a6c52..000000000 --- a/src/app/puzzle/vpiececarrousellayer.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/************************************************************************ - ** - ** @file vpiececarrousellayer.cpp - ** @author Ronan Le Tiec - ** @date 25 4, 2020 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2020 Valentina project - ** All Rights Reserved. - ** - ** Valentina 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 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#include "vpiececarrousellayer.h" -#include "vpiececarrousel.h" -#include "../vmisc/backport/qoverload.h" - -#include - -#include - -Q_LOGGING_CATEGORY(pCarrouselLayer, "p.carrouselLayer") - -//--------------------------------------------------------------------------------------------------------------------- -VPieceCarrouselLayer::VPieceCarrouselLayer(VPuzzleLayer *layer, VPieceCarrousel *carrousel) : - m_layer(layer), - m_carrousel(carrousel), - m_carrouselPieces(QList()) -{ - Init(); -} - -//--------------------------------------------------------------------------------------------------------------------- -VPieceCarrouselLayer::~VPieceCarrouselLayer() -{ - Clear(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselLayer::Init() -{ - // initiales the structure - QVBoxLayout *layoutPiecesLayout = new QVBoxLayout(); - layoutPiecesLayout->setMargin(0); - setLayout(layoutPiecesLayout); - - // then refresh the content - Refresh(); - - // add the connections - connect(m_layer, &VPuzzleLayer::PieceAdded, this, &VPieceCarrouselLayer::on_PieceAdded); - connect(m_layer, &VPuzzleLayer::PieceRemoved, this, &VPieceCarrouselLayer::on_PieceRemoved); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselLayer::Refresh() -{ - Clear(); - - // Updates the carrousel pieces from the pieces list - QList pieces = m_layer->GetPieces(); - - // sort the pieces in alphabetical order - std::sort(pieces.begin(), pieces.end(), - [](const VPuzzlePiece* a, const VPuzzlePiece* b) -> bool { return a->GetName() < b->GetName();}); - - // create the corresponding carrousel pieces - - bool _isVisible = isVisible(); - setVisible(true); - for (auto piece : pieces) - { - VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece, this); - m_carrouselPieces.append(carrouselPiece); - layout()->addWidget(carrouselPiece); - carrouselPiece->CleanPreview(); // fitInView only works if the widget is displayed. - } - setVisible(_isVisible); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselLayer::Clear() -{ - // Removes and deletes the carrousel pieces from the layer - while (!m_carrouselPieces.isEmpty()) - { - VPieceCarrouselPiece *carrouselPiece = m_carrouselPieces.takeLast(); - - if(carrouselPiece != nullptr) - { - layout()->removeWidget(carrouselPiece); - delete carrouselPiece; - } - } - -} - -//--------------------------------------------------------------------------------------------------------------------- -QList VPieceCarrouselLayer::GetCarrouselPieces() -{ - return m_carrouselPieces; -} - -//--------------------------------------------------------------------------------------------------------------------- -VPieceCarrousel* VPieceCarrouselLayer::GetCarrousel() -{ - return m_carrousel; -} - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayer* VPieceCarrouselLayer::GetLayer() -{ - return m_layer; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselLayer::on_PieceAdded(VPuzzlePiece* piece) -{ - Q_UNUSED(piece) - - // TODO/ FIXME: see if we find a solution more efficient refreshing the complete layout everytime. - - Refresh(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselLayer::on_PieceRemoved(VPuzzlePiece* piece) -{ - for (auto carrouselPiece : m_carrouselPieces) - { - if(carrouselPiece->GetPiece() == piece) - { - m_carrouselPieces.removeAll(carrouselPiece); - layout()->removeWidget(carrouselPiece); - delete carrouselPiece; - - return; - } - } -} diff --git a/src/app/puzzle/vpiececarrousellayer.h b/src/app/puzzle/vpiececarrousellayer.h deleted file mode 100644 index 4c65455ae..000000000 --- a/src/app/puzzle/vpiececarrousellayer.h +++ /dev/null @@ -1,84 +0,0 @@ -/************************************************************************ - ** - ** @file vpiececarrousellayer.h - ** @author Ronan Le Tiec - ** @date 25 4, 2020 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2020 Valentina project - ** All Rights Reserved. - ** - ** Valentina 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 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#ifndef VPIECECARROUSELLAYER_H -#define VPIECECARROUSELLAYER_H - -#include -#include "vpuzzlelayer.h" -#include "vpiececarrouselpiece.h" - -class VPieceCarrousel; - -class VPieceCarrouselLayer : public QWidget -{ - Q_OBJECT -public: - VPieceCarrouselLayer(VPuzzleLayer *layer, VPieceCarrousel *carrousel); - ~VPieceCarrouselLayer(); - - void Init(); - void Refresh(); - - /** - * @brief Clear it clears the carrousel layer from its pieces - */ - void Clear(); - - QList GetCarrouselPieces(); - - VPieceCarrousel* GetCarrousel(); - - /** - * @brief GetPuzzleLayer Returns the corresponding VPuzzleLayer - * @return the VPuzzleLayer - */ - VPuzzleLayer* GetLayer(); - -private: - Q_DISABLE_COPY(VPieceCarrouselLayer) - - VPuzzleLayer *m_layer; - VPieceCarrousel *m_carrousel; - QList m_carrouselPieces; - -private slots: - - /** - * @brief on_PieceUpdated This slot is called when a piece was added - */ - void on_PieceAdded(VPuzzlePiece* piece); - - /** - * @brief on_PieceUpdated This slot is called when a piece was removed - */ - void on_PieceRemoved(VPuzzlePiece* piece); - -}; - -#endif // VPIECECARROUSELLAYER_H diff --git a/src/app/puzzle/vpiececarrouselpiece.cpp b/src/app/puzzle/vpiececarrouselpiece.cpp deleted file mode 100644 index 85958ab63..000000000 --- a/src/app/puzzle/vpiececarrouselpiece.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/************************************************************************ - ** - ** @file vpiececarrouselpiece.cpp - ** @author Ronan Le Tiec - ** @date 25 4, 2020 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2020 Valentina project - ** All Rights Reserved. - ** - ** Valentina 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 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#include "vpiececarrouselpiece.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "vpuzzlemimedatapiece.h" -#include "vpiececarrousellayer.h" -#include "vpiececarrousel.h" - -#include - -Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece") - - -//--------------------------------------------------------------------------------------------------------------------- -VPieceCarrouselPiece::VPieceCarrouselPiece(VPuzzlePiece *piece, VPieceCarrouselLayer *carrouselLayer) : - m_piece(piece), - m_carrouselLayer(carrouselLayer), - m_dragStart(QPoint()) -{ - Init(); -} - - -//--------------------------------------------------------------------------------------------------------------------- -VPieceCarrouselPiece::~VPieceCarrouselPiece() -{ - delete m_piecePreview; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiece::Init() -{ - // Define the structure - setFixedSize(124,128); - QVBoxLayout *pieceLayout = new QVBoxLayout(); - pieceLayout->setMargin(0); - pieceLayout->setSpacing(0); - setLayout(pieceLayout); - - setStyleSheet("background-color:white; border: 2px solid transparent;"); - - // define the preview of the piece - m_piecePreview = new VPieceCarrouselPiecePreview(this); - - // m_graphicsView = new VMainGraphicsView(this); - // --> undefined reference to 'VMainGraphicsView::VMainGraphicView(QWidget*)' - QGraphicsScene *graphicsScene = new QGraphicsScene(this); - m_piecePreview->setScene(graphicsScene); - m_piecePreview->setFixedSize(120,100); - m_piecePreview->setStyleSheet("border: 4px solid transparent;"); - m_piecePreview->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - - // define the label - m_label = new QLabel(); - m_label->sizePolicy(); - m_label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); - m_label->setFixedSize(120,24); - m_label->setStyleSheet("border: 0px;"); - m_label->setMouseTracking(false); - - pieceLayout->addWidget(m_piecePreview); - pieceLayout->addWidget(m_label); - - - // connect the signals - connect(m_piece, &VPuzzlePiece::SelectionChanged, this, &VPieceCarrouselPiece::on_PieceSelectionChanged); - - // then refresh the data - Refresh(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiece::CleanPreview() -{ - m_piecePreview->fitInView(m_piecePreview->scene()->sceneRect(), Qt::KeepAspectRatio); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiece::Refresh() -{ - // update the graphic view / the scene - - QVector points = m_piece->GetSeamLine(); - if(points.isEmpty()) - { - points = m_piece->GetCuttingLine(); - } - - QPen pen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); - pen.setCosmetic(true); - QBrush noBrush(Qt::NoBrush); - - QPainterPath path; - path.moveTo(points.first()); - for (int i = 1; i < points.size(); ++i) - path.lineTo(points.at(i)); - m_piecePreview->scene()->addPath(path, pen, noBrush); - - m_piecePreview->fitInView(m_piecePreview->scene()->sceneRect(), Qt::KeepAspectRatio); - - // update the label of the piece - QFontMetrics metrix(m_label->font()); - int width = m_label->width() - 8; - QString clippedText = metrix.elidedText(m_piece->GetName(), Qt::ElideRight, width); - m_label->setText(clippedText); - - // set the tooltip - setToolTip(m_piece->GetName()); - - // set the selection state correctly. - on_PieceSelectionChanged(); -} - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzlePiece * VPieceCarrouselPiece::GetPiece() -{ - return m_piece; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiece::on_PieceSelectionChanged() -{ - if(m_piece->GetIsSelected()) - { - setStyleSheet("background-color:white; border: 2px solid red;"); - } - else - { - setStyleSheet("background-color:white; border: 2px solid transparent;"); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiece::mousePressEvent(QMouseEvent *event) -{ - qCDebug(pCarrouselPiece, "mouse pressed"); - - - if (event->button() == Qt::LeftButton) - { - if(!(event->modifiers() & Qt::ControlModifier)) - { - m_carrouselLayer->GetCarrousel()->ClearSelection(); - m_piece->SetIsSelected(true); - } - else - { - m_piece->SetIsSelected(!m_piece->GetIsSelected()); - } - - m_dragStart = event->pos(); - } -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiece::mouseMoveEvent(QMouseEvent *event) -{ - if (!(event->buttons() & Qt::LeftButton)) - { - return; - } - - if(m_piece->GetLayer() != m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer()) - { - return; - } - - if((event->pos() - m_dragStart).manhattanLength() < QApplication::startDragDistance()) - { - return; - } - - // make sure the multiple selection is removed - m_carrouselLayer->GetCarrousel()->ClearSelection(); - m_piece->SetIsSelected(true); - - // starts the dragging - QDrag *drag = new QDrag(this); - VPuzzleMimeDataPiece *mimeData = new VPuzzleMimeDataPiece(); - mimeData->SetPiecePtr(m_piece); - mimeData->setObjectName("piecePointer"); - - // in case we would want to have the pieces original size: - //drag->setHotSpot(QPoint(0,0)); - //QPixmap pixmap(m_piecePreview->sceneRect().size().toSize()); - - QPixmap pixmap(112,92); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - painter.setRenderHint(QPainter::Antialiasing); - m_piecePreview->scene()->render(&painter); - - drag->setPixmap(pixmap); - drag->setMimeData(mimeData); - drag->exec(); -} - - - - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiece::contextMenuEvent(QContextMenuEvent *event) -{ - QMenu contextMenu; - - VPuzzleLayer* unplacedLayer = m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer(); - QList layers = m_piece->GetLayer()->GetLayout()->GetLayers(); - - // move to layer actions -- TODO : To be tested properly when we have several layers - layers.removeAll(m_piece->GetLayer()); - if(layers.count() > 0) - { - QMenu *moveMenu = contextMenu.addMenu(tr("Move to")); - - // TODO order in alphabetical order - - for (auto layer : layers) - { - QAction* moveToLayer = moveMenu->addAction(layer->GetName()); - QVariant data = QVariant::fromValue(layer); - moveToLayer->setData(data); - - connect(moveToLayer, &QAction::triggered, this, &VPieceCarrouselPiece::on_ActionPieceMovedToLayer); - } - } - - // remove from layout action - if(m_piece->GetLayer() != unplacedLayer) - { - QAction *removeAction = contextMenu.addAction(tr("Remove from Layout")); - QVariant data = QVariant::fromValue(m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer()); - removeAction->setData(data); - connect(removeAction, &QAction::triggered, this, &VPieceCarrouselPiece::on_ActionPieceMovedToLayer); - } - - contextMenu.exec(event->globalPos()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiece::on_ActionPieceMovedToLayer() -{ - QAction *act = qobject_cast(sender()); - QVariant v = act->data(); - VPuzzleLayer *layer = v.value(); - if(layer != nullptr) - { - layer->GetLayout()->MovePieceToLayer(m_piece, layer); - } -} diff --git a/src/app/puzzle/vpiececarrouselpiece.h b/src/app/puzzle/vpiececarrouselpiece.h deleted file mode 100644 index 96264e0d0..000000000 --- a/src/app/puzzle/vpiececarrouselpiece.h +++ /dev/null @@ -1,96 +0,0 @@ -/************************************************************************ - ** - ** @file vpiececarrouselpiece.h - ** @author Ronan Le Tiec - ** @date 25 4, 2020 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2020 Valentina project - ** All Rights Reserved. - ** - ** Valentina 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 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ -#ifndef VPIECECARROUSELPIECE_H -#define VPIECECARROUSELPIECE_H - -#include -#include -#include -#include - -#include "vpuzzlepiece.h" -#include "vpiececarrouselpiecepreview.h" - - -class VPieceCarrouselLayer; - -class VPieceCarrouselPiece : public QFrame -{ - Q_OBJECT -public: - explicit VPieceCarrouselPiece(VPuzzlePiece *piece, VPieceCarrouselLayer *carrouselLayer); - ~VPieceCarrouselPiece(); - - void Init(); - void Refresh(); - /** - * @brief CleanPiecesPreview fitInView of the qGraphicsView of the pieces works properly - * only when the piece is in place in the layer and we call it from the layer. - */ - void CleanPreview(); - - /** - * @brief GetLayoutPiece Returns the corresponding layout piece - * @return the corresponding layout piece - */ - VPuzzlePiece * GetPiece(); - -public slots: - void on_PieceSelectionChanged(); - -protected: - void mousePressEvent(QMouseEvent *event) override; - - void mouseMoveEvent(QMouseEvent *event) override; - - void contextMenuEvent(QContextMenuEvent *event) override; - -private slots: - /** - * @brief on_ActionPieceMovedToLayer Slot called when the piece is moved via the - * context menu to anoter layer - */ - void on_ActionPieceMovedToLayer(); - -private: - Q_DISABLE_COPY(VPieceCarrouselPiece) - - VPuzzlePiece *m_piece; - - VPieceCarrouselLayer *m_carrouselLayer; - - QLabel *m_label{nullptr}; - VPieceCarrouselPiecePreview *m_piecePreview{nullptr}; - - QPoint m_dragStart; - -private slots: - -}; - -#endif // VPIECECARROUSELPIECE_H diff --git a/src/app/puzzle/vpiececarrouselpiecepreview.cpp b/src/app/puzzle/vpiececarrouselpiecepreview.cpp deleted file mode 100644 index f68af933f..000000000 --- a/src/app/puzzle/vpiececarrouselpiecepreview.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************ - ** - ** @file vpiececarrouselpiecepreview.cpp - ** @author Ronan Le Tiec - ** @date 3 5, 2020 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2020 Valentina project - ** All Rights Reserved. - ** - ** Valentina 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 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#include "vpiececarrouselpiecepreview.h" - -#include - -//--------------------------------------------------------------------------------------------------------------------- -VPieceCarrouselPiecePreview::VPieceCarrouselPiecePreview(QWidget *parent): - QGraphicsView(parent) -{ - -} -//--------------------------------------------------------------------------------------------------------------------- -VPieceCarrouselPiecePreview::~VPieceCarrouselPiecePreview() -{ - -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiecePreview::mousePressEvent(QMouseEvent *event) -{ - event->ignore(); -} -//--------------------------------------------------------------------------------------------------------------------- -void VPieceCarrouselPiecePreview::mouseMoveEvent(QMouseEvent *event) -{ - event->ignore(); -} - diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp new file mode 100644 index 000000000..fe77d2959 --- /dev/null +++ b/src/app/puzzle/vplayout.cpp @@ -0,0 +1,207 @@ +/************************************************************************ + ** + ** @file vplayout.cpp + ** @author Ronan Le Tiec + ** @date 13 4, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#include "vplayout.h" +#include "vppiecelist.h" +#include "vppiece.h" +#include "vpsheet.h" + + +#include + +Q_LOGGING_CATEGORY(pLayout, "p.layout") + +//--------------------------------------------------------------------------------------------------------------------- +VPLayout::VPLayout() : + m_unplacedPieceList(new VPPieceList(this)), + m_sheets(QList()) +{ + m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces")); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPLayout::~VPLayout() +{ + qDeleteAll(m_sheets); + delete m_unplacedPieceList; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPPieceList* VPLayout::GetUnplacedPieceList() +{ + return m_unplacedPieceList; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPSheet* VPLayout::AddSheet() +{ + VPSheet *newSheet = new VPSheet(this); + m_sheets.append(newSheet); + return newSheet; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPSheet* VPLayout::AddSheet(VPSheet *sheet) +{ + m_sheets.append(sheet); + return sheet; +} + +//--------------------------------------------------------------------------------------------------------------------- +QList VPLayout::GetSheets() +{ + return m_sheets; +} + +//--------------------------------------------------------------------------------------------------------------------- +QList VPLayout::GetSelectedPieces() +{ + QList result = QList(); + + QList pieceLists = QList(); + pieceLists.append(m_unplacedPieceList); + for (auto sheet : m_sheets) + { + pieceLists.append(sheet->GetPieceList()); + } + + for (auto pieceList : pieceLists) + { + for (auto piece : pieceList->GetPieces()) + { + if(piece->GetIsSelected()) + { + result.append(piece); + } + } + } + + return result; +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetUnit(Unit unit) +{ + m_unit = unit; +} + +//--------------------------------------------------------------------------------------------------------------------- +Unit VPLayout::GetUnit() const +{ + return m_unit; +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetWarningSuperpositionOfPieces(bool state) +{ + m_warningSuperpositionOfPieces = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPLayout::GetWarningSuperpositionOfPieces() const +{ + return m_warningSuperpositionOfPieces; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetWarningPiecesOutOfBound(bool state) +{ + m_warningPiecesOutOfBound = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPLayout::GetWarningPiecesOutOfBound() const +{ + return m_warningPiecesOutOfBound; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::ClearSelection() +{ + m_unplacedPieceList->ClearSelection(); + + for (auto sheet : m_sheets) + { + sheet->ClearSelection(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList) +{ + if(m_unplacedPieceList != pieceList) + { + m_unplacedPieceList->ClearSelection(); + } + + for (auto sheet : m_sheets) + { + if(sheet->GetPieceList() != pieceList) + { + sheet->ClearSelection(); + } + } +} + + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList) +{ + VPPieceList* pieceListBefore = piece->GetPieceList(); + + if(pieceListBefore != nullptr) + { + piece->GetPieceList()->RemovePiece(piece); + } + pieceList->AddPiece(piece); + + // signal, that a piece was moved + emit PieceMovedToPieceList(piece, pieceListBefore,pieceList); +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayout::SetFocusedSheet(VPSheet *focusedSheet) +{ + if(focusedSheet == nullptr) + { + m_focusedSheet = m_sheets.first(); + } + else + { + m_focusedSheet = focusedSheet; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VPSheet* VPLayout::GetFocusedSheet() +{ + return m_focusedSheet; +} diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h new file mode 100644 index 000000000..a81017bb8 --- /dev/null +++ b/src/app/puzzle/vplayout.h @@ -0,0 +1,147 @@ +/************************************************************************ + ** + ** @file vplayout.h + ** @author Ronan Le Tiec + ** @date 13 4, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#ifndef VPLAYOUT_H +#define VPLAYOUT_H + + +#include + +#include "def.h" + +class VPPieceList; +class VPPiece; +class VPSheet; + +class VPLayout : public QObject +{ + Q_OBJECT +public: + VPLayout(); + virtual ~VPLayout(); + + /** + * @brief GetUnplacedPieceList Returns the piece list of unplaced pieces + * @return the unplaced pieces list + */ + VPPieceList* GetUnplacedPieceList(); + + VPSheet* AddSheet(); + VPSheet* AddSheet(VPSheet *sheet); + QList GetSheets(); + + /** + * @brief GetSelectedPieces Returns the list of the selected pieces + * @return the selected pieces + */ + QList GetSelectedPieces(); + + /** + * @brief SetUnit Sets the unit of the layout to the given unit + * @param unit the new unit + */ + void SetUnit(Unit unit); + + /** + * @brief GetUnit Returns the current unit of the layout + * @return the unit + */ + Unit GetUnit() const; + + void SetWarningSuperpositionOfPieces(bool state); + bool GetWarningSuperpositionOfPieces() const; + + void SetWarningPiecesOutOfBound(bool state); + bool GetWarningPiecesOutOfBound() const; + + /** + * @brief ClearSelection goes through the unplaced pieces and through the sheets and calls + * SetIsSelected(false) for the pieces that were selected. + */ + void ClearSelection(); + + /** + * @brief ClearSelectionExceptForPieceList same as clearSelection but it leaves the selection + * for the given piece list like it ist. + * + * @param pieceList the piece list to let be the way it is. + */ + void ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList); + + /** + * @brief MovePieceToPieceList Moves the given piece to the given piece list + * @param piece the piece to move + * @param pieceList the piece list to move the piece to + */ + void MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList); + + /** + * @brief SetFocusedSheet Sets the focused sheet, to which pieces are added from the carrousel via drag + * and drop + * @param focusedSheet the new active sheet. If nullptr, then it sets automaticaly the first sheet from m_sheets + */ + void SetFocusedSheet(VPSheet *focusedSheet = nullptr); + + /** + * @brief GetFocusedSheet Returns the focused sheet, to which pieces are added from the carrousel via drag + * and drop + * @return the focused sheet + */ + VPSheet* GetFocusedSheet(); + + +signals: + + void PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter); + +private: + Q_DISABLE_COPY(VPLayout) + + VPPieceList *m_unplacedPieceList; + + QList m_sheets; + + /** + TODO : To be replaced by m_focusedSheet + * @brief m_focusedPieceList pointer the the focused piece list, to which pieces will be + * added via drag and drop, or if no piece list is defined. + */ + VPPieceList *m_focusedPieceList{nullptr}; + + + VPSheet *m_focusedSheet{nullptr}; + + // format + Unit m_unit{Unit::Cm}; + + bool m_warningSuperpositionOfPieces{false}; + bool m_warningPiecesOutOfBound{false}; + + +}; + +#endif // VPLAYOUT_H diff --git a/src/app/puzzle/vpuzzlemaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp similarity index 69% rename from src/app/puzzle/vpuzzlemaingraphicsview.cpp rename to src/app/puzzle/vpmaingraphicsview.cpp index 4be5cf375..a114a8ff0 100644 --- a/src/app/puzzle/vpuzzlemaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlemaingraphicsview.cpp + ** @file vpmaingraphicsview.cpp ** @author Ronan Le Tiec ** @date 3 5, 2020 ** @@ -26,14 +26,16 @@ ** *************************************************************************/ -#include "vpuzzlemaingraphicsview.h" +#include "vpmaingraphicsview.h" #include #include #include -#include "vpuzzlemimedatapiece.h" -#include "vpuzzlelayer.h" +#include "vpmimedatapiece.h" +#include "vppiecelist.h" +#include "vplayout.h" +#include "vpsheet.h" #include "../vwidgets/vmaingraphicsscene.h" #include @@ -42,37 +44,38 @@ Q_LOGGING_CATEGORY(pMainGraphicsView, "p.mainGraphicsView") //--------------------------------------------------------------------------------------------------------------------- -VPuzzleMainGraphicsView::VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget *parent) : +VPMainGraphicsView::VPMainGraphicsView(VPLayout *layout, QWidget *parent) : VMainGraphicsView(parent), m_layout(layout) { + // TODO : list of scenes m_scene = new VMainGraphicsScene(this); setScene(m_scene); - m_graphicsLayout = new VPuzzleGraphicsLayout(layout); - m_graphicsLayout->setPos(0, 0); - m_scene->addItem(m_graphicsLayout); + m_graphicsSheet = new VPGraphicsSheet(layout->GetFocusedSheet()); + m_graphicsSheet->setPos(0, 0); + m_scene->addItem(m_graphicsSheet); setAcceptDrops(true); // add the connections - connect(m_layout, &VPuzzleLayout::PieceMovedToLayer, this, &VPuzzleMainGraphicsView::on_PieceMovedToLayer); + connect(m_layout, &VPLayout::PieceMovedToPieceList, this, &VPMainGraphicsView::on_PieceMovedToPieceList); connect(m_scene, &VMainGraphicsScene::selectionChanged, this, - &VPuzzleMainGraphicsView::on_SceneSelectionChanged); + &VPMainGraphicsView::on_SceneSelectionChanged); } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleMainGraphicsView::RefreshLayout() +void VPMainGraphicsView::RefreshLayout() { // FIXME: Is that the way to go? - m_graphicsLayout->update(); + m_graphicsSheet->update(); m_scene->update(); } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleMainGraphicsView::dragEnterEvent(QDragEnterEvent *event) +void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event) { const QMimeData *mime = event->mimeData(); @@ -84,7 +87,7 @@ void VPuzzleMainGraphicsView::dragEnterEvent(QDragEnterEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleMainGraphicsView::dragMoveEvent(QDragMoveEvent *event) +void VPMainGraphicsView::dragMoveEvent(QDragMoveEvent *event) { const QMimeData *mime = event->mimeData(); @@ -95,7 +98,7 @@ void VPuzzleMainGraphicsView::dragMoveEvent(QDragMoveEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleMainGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) +void VPMainGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) { event->accept(); } @@ -103,7 +106,7 @@ void VPuzzleMainGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleMainGraphicsView::dropEvent(QDropEvent *event) +void VPMainGraphicsView::dropEvent(QDropEvent *event) { const QMimeData *mime = event->mimeData(); @@ -111,9 +114,9 @@ void VPuzzleMainGraphicsView::dropEvent(QDropEvent *event) if(mime->objectName() == "piecePointer") { - const VPuzzleMimeDataPiece *mimePiece = qobject_cast (mime); + const VPMimeDataPiece *mimePiece = qobject_cast (mime); - VPuzzlePiece *piece = mimePiece->GetPiecePtr(); + VPPiece *piece = mimePiece->GetPiecePtr(); if(piece != nullptr) { qCDebug(pMainGraphicsView(), "element dropped, %s", qUtf8Printable(piece->GetName())); @@ -122,42 +125,42 @@ void VPuzzleMainGraphicsView::dropEvent(QDropEvent *event) QPoint point = event->pos(); piece->SetPosition(mapToScene(point)); - // change the layer of the piece - VPuzzleLayer *focusedLayer = m_layout->GetFocusedLayer(); - if(focusedLayer != nullptr) + // change the piecelist of the piece + VPPieceList *focusedPieceList = m_layout->GetFocusedSheet()->GetPieceList(); + if(focusedPieceList != nullptr) { - m_layout->MovePieceToLayer(piece, focusedLayer); + m_layout->MovePieceToPieceList(piece, focusedPieceList); } } } } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleMainGraphicsView::keyPressEvent(QKeyEvent *event) +void VPMainGraphicsView::keyPressEvent(QKeyEvent *event) { if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) { - QList tmpGraphicsPieces = m_graphicsPieces; + QList tmpGraphicsPieces = m_graphicsPieces; for(auto graphicsPiece : tmpGraphicsPieces) { - VPuzzlePiece *piece = graphicsPiece->GetPiece(); + VPPiece *piece = graphicsPiece->GetPiece(); if(piece->GetIsSelected()) { piece->SetIsSelected(false); - m_layout->MovePieceToLayer(piece, m_layout->GetUnplacedPiecesLayer()); + m_layout->MovePieceToPieceList(piece, m_layout->GetUnplacedPieceList()); } } } } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleMainGraphicsView::on_PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleLayer *layerBefore, VPuzzleLayer *layerAfter) +void VPMainGraphicsView::on_PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter) { - Q_UNUSED(layerBefore) + Q_UNUSED(pieceListBefore) - VPuzzleGraphicsPiece *_graphicsPiece = nullptr; + VPGraphicsPiece *_graphicsPiece = nullptr; for(auto graphicPiece : m_graphicsPieces) { if(graphicPiece->GetPiece() == piece) @@ -166,16 +169,16 @@ void VPuzzleMainGraphicsView::on_PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleL } } - if(layerAfter == m_layout->GetUnplacedPiecesLayer() && _graphicsPiece != nullptr) + if(pieceListAfter == m_layout->GetUnplacedPieceList() && _graphicsPiece != nullptr) { scene()->removeItem(_graphicsPiece); m_graphicsPieces.removeAll(_graphicsPiece); } - else if(layerAfter != m_layout->GetUnplacedPiecesLayer()) + else if(pieceListAfter != m_layout->GetUnplacedPieceList()) { if(_graphicsPiece == nullptr) { - _graphicsPiece = new VPuzzleGraphicsPiece(piece); + _graphicsPiece = new VPGraphicsPiece(piece); m_graphicsPieces.append(_graphicsPiece); } @@ -188,11 +191,11 @@ void VPuzzleMainGraphicsView::on_PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleL } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleMainGraphicsView::on_SceneSelectionChanged() +void VPMainGraphicsView::on_SceneSelectionChanged() { // most of the selection behaviour taks place automatically // but we need to make sure that the unplaced pieces are unselected when the scene selection has changed // because as they are not part of the scene, they are not updated - m_layout->GetUnplacedPiecesLayer()->ClearSelection(); + m_layout->GetUnplacedPieceList()->ClearSelection(); } diff --git a/src/app/puzzle/vpuzzlemaingraphicsview.h b/src/app/puzzle/vpmaingraphicsview.h similarity index 68% rename from src/app/puzzle/vpuzzlemaingraphicsview.h rename to src/app/puzzle/vpmaingraphicsview.h index bccff359c..15709c520 100644 --- a/src/app/puzzle/vpuzzlemaingraphicsview.h +++ b/src/app/puzzle/vpmaingraphicsview.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlemaingraphicsview.h + ** @file vpmaingraphicsview.h ** @author Ronan Le Tiec ** @date 3 5, 2020 ** @@ -26,22 +26,22 @@ ** *************************************************************************/ -#ifndef VPUZZLEMAINGRAPHICSVIEW_H -#define VPUZZLEMAINGRAPHICSVIEW_H +#ifndef VPMAINGRAPHICSVIEW_H +#define VPMAINGRAPHICSVIEW_H -#include "vpuzzlegraphicslayout.h" -#include "vpuzzlegraphicspiece.h" +#include "vpgraphicssheet.h" +#include "vpgraphicspiece.h" #include "../vwidgets/vmaingraphicsview.h" class VMainGraphicsScene; -class VPuzzleMainGraphicsView : public VMainGraphicsView +class VPMainGraphicsView : public VMainGraphicsView { Q_OBJECT public: - VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget *parent); - ~VPuzzleMainGraphicsView() = default; + VPMainGraphicsView(VPLayout *layout, QWidget *parent); + ~VPMainGraphicsView() = default; /** * @brief RefreshLayout Refreshes the rectangles for the layout border and the margin @@ -58,13 +58,13 @@ protected: private slots: /** - * @brief on_PieceMovedToLayer The slot is called when the given piece was moved from the given layer to the other - * given layer + * @brief on_PieceMovedToPieceList The slot is called when the given piece was moved from the given piece list to the other + * given piece list * @param piece the piece that was moved - * @param layerBefore the layer before the move - * @param layerAfter the layer after the move + * @param pieceListBefore the piece list before the move + * @param pieceListAfter the piece list after the move */ - void on_PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleLayer *layerBefore, VPuzzleLayer *layerAfter); + void on_PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter); /** * @brief on_SceneSelectionChanged Slot is called when the scene selection has changed @@ -72,15 +72,15 @@ private slots: void on_SceneSelectionChanged(); private: - Q_DISABLE_COPY(VPuzzleMainGraphicsView) + Q_DISABLE_COPY(VPMainGraphicsView) VMainGraphicsScene *m_scene{nullptr}; - VPuzzleGraphicsLayout *m_graphicsLayout{nullptr}; - VPuzzleLayout *m_layout{nullptr}; + VPGraphicsSheet *m_graphicsSheet{nullptr}; + VPLayout *m_layout{nullptr}; - QList m_graphicsPieces{}; + QList m_graphicsPieces{}; }; -#endif // VPUZZLEMAINGRAPHICVIEW_H +#endif // VPMAINGRAPHICSVIEW_H diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp similarity index 73% rename from src/app/puzzle/puzzlemainwindow.cpp rename to src/app/puzzle/vpmainwindow.cpp index 874477d53..a2bd21750 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file puzzlemainwindow.cpp + ** @file vpmainwindow.cpp ** @author Roman Telezhynskyi ** @date 16 2, 2020 ** @@ -25,20 +25,22 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#include "puzzlemainwindow.h" +#include "vpmainwindow.h" #include +#include -#include "ui_puzzlemainwindow.h" -#include "dialogs/dialogaboutpuzzle.h" -#include "xml/vpuzzlelayoutfilewriter.h" -#include "xml/vpuzzlelayoutfilereader.h" -#include "puzzleapplication.h" +#include "ui_vpmainwindow.h" +#include "dialogs/vpdialogabout.h" +#include "xml/vplayoutfilewriter.h" +#include "xml/vplayoutfilereader.h" +#include "vpapplication.h" #include "../vlayout/vrawlayout.h" #include "../vmisc/vsysexits.h" #include "../vmisc/projectversion.h" #include "../ifc/xml/vlayoutconverter.h" #include "../ifc/exception/vexception.h" +#include "vpsheet.h" #include @@ -51,18 +53,24 @@ Q_LOGGING_CATEGORY(pWindow, "p.window") QT_WARNING_POP //--------------------------------------------------------------------------------------------------------------------- -PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *parent) : +VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : QMainWindow(parent), - ui(new Ui::PuzzleMainWindow), + ui(new Ui::VPMainWindow), m_cmd(cmd) { + m_layout = new VPLayout(); - m_layout = new VPuzzleLayout(); + // create a standard sheet + VPSheet *sheet = new VPSheet(m_layout); + sheet->SetName(QObject::tr("Sheet #1")); + m_layout->AddSheet(sheet); + m_layout->SetFocusedSheet(); // ----- for test purposes, to be removed------------------ - m_layout->SetLayoutMarginsConverted(2, 2, 2, 2); - m_layout->SetLayoutSizeConverted(30.0, 45); - m_layout->SetPiecesGapConverted(1); + sheet->SetSheetMarginsConverted(2, 2, 2, 2); + sheet->SetSheetSizeConverted(30.0, 45); + sheet->SetPiecesGapConverted(1); + m_layout->SetUnit(Unit::Cm); m_layout->SetWarningSuperpositionOfPieces(true); // -------------------------------------------------------- @@ -71,7 +79,7 @@ PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *pa InitMenuBar(); InitProperties(); - InitPieceCarrousel(); + InitCarrousel(); InitMainGraphics(); @@ -81,14 +89,14 @@ PuzzleMainWindow::PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *pa } //--------------------------------------------------------------------------------------------------------------------- -PuzzleMainWindow::~PuzzleMainWindow() +VPMainWindow::~VPMainWindow() { delete ui; - delete m_pieceCarrousel; + delete m_carrousel; } //--------------------------------------------------------------------------------------------------------------------- -bool PuzzleMainWindow::LoadFile(QString path) +bool VPMainWindow::LoadFile(QString path) { try { @@ -105,11 +113,11 @@ bool PuzzleMainWindow::LoadFile(QString path) QFile file(path); file.open(QIODevice::ReadOnly); - QScopedPointer fileReader(new VPuzzleLayoutFileReader()); + QScopedPointer fileReader(new VPLayoutFileReader()); if(m_layout == nullptr) { - m_layout = new VPuzzleLayout(); + m_layout = new VPLayout(); } fileReader->ReadFile(m_layout, &file); @@ -120,12 +128,12 @@ bool PuzzleMainWindow::LoadFile(QString path) } //--------------------------------------------------------------------------------------------------------------------- -bool PuzzleMainWindow::SaveFile(const QString &path) +bool VPMainWindow::SaveFile(const QString &path) { QFile file(path); file.open(QIODevice::WriteOnly); - VPuzzleLayoutFileWriter *fileWriter = new VPuzzleLayoutFileWriter(); + VPLayoutFileWriter *fileWriter = new VPLayoutFileWriter(); fileWriter->WriteFile(m_layout, &file); // TODO / FIXME : better return value and error handling @@ -134,7 +142,7 @@ bool PuzzleMainWindow::SaveFile(const QString &path) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts) +void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts) { VRawLayout rawLayoutReader; @@ -163,11 +171,11 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts) // TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece() - VPuzzlePiece *piece = CreatePiece(rawPiece); - m_layout->GetUnplacedPiecesLayer()->AddPiece(piece); + VPPiece *piece = CreatePiece(rawPiece); + m_layout->GetUnplacedPieceList()->AddPiece(piece); } - m_pieceCarrousel->Refresh(); + m_carrousel->Refresh(); } else { @@ -182,9 +190,9 @@ void PuzzleMainWindow::ImportRawLayouts(const QStringList &rawLayouts) } //--------------------------------------------------------------------------------------------------------------------- -VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece) +VPPiece* VPMainWindow::CreatePiece(const VLayoutPiece &rawPiece) { - VPuzzlePiece *piece = new VPuzzlePiece(); + VPPiece *piece = new VPPiece(); piece->SetName(rawPiece.GetName()); piece->SetUuid(rawPiece.GetUUID()); @@ -201,22 +209,22 @@ VPuzzlePiece* PuzzleMainWindow::CreatePiece(const VLayoutPiece &rawPiece) // TODO : set all the information we need for the piece! // - connect(piece, &VPuzzlePiece::SelectionChanged, this, &PuzzleMainWindow::on_PieceSelectionChanged); - connect(piece, &VPuzzlePiece::PositionChanged, this, &PuzzleMainWindow::on_PiecePositionChanged); - connect(piece, &VPuzzlePiece::RotationChanged, this, &PuzzleMainWindow::on_PieceRotationChanged); + connect(piece, &VPPiece::SelectionChanged, this, &VPMainWindow::on_PieceSelectionChanged); + connect(piece, &VPPiece::PositionChanged, this, &VPMainWindow::on_PiecePositionChanged); + connect(piece, &VPPiece::RotationChanged, this, &VPMainWindow::on_PieceRotationChanged); return piece; } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::InitMenuBar() +void VPMainWindow::InitMenuBar() { // most of the actions are connected through name convention (auto-connection) // -------------------- connects the actions for the file menu - connect(ui->actionExit, &QAction::triggered, this, &PuzzleMainWindow::close); + connect(ui->actionExit, &QAction::triggered, this, &VPMainWindow::close); // -------------------- connects the actions for the edit menu // TODO : initialise the undo / redo @@ -231,28 +239,27 @@ void PuzzleMainWindow::InitMenuBar() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::InitProperties() +void VPMainWindow::InitProperties() { InitPropertyTabCurrentPiece(); InitPropertyTabLayout(); - InitPropertyTabLayers(); InitPropertyTabTiles(); } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::InitPropertyTabCurrentPiece() +void VPMainWindow::InitPropertyTabCurrentPiece() { // ------------------------------ placement ----------------------------------- connect(ui->doubleSpinBoxCurrentPieceBoxPositionX, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::on_CurrentPiecePositionEdited); + &VPMainWindow::on_CurrentPiecePositionEdited); connect(ui->doubleSpinBoxCurrentPieceBoxPositionY, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::on_CurrentPiecePositionEdited); + &VPMainWindow::on_CurrentPiecePositionEdited); } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::InitPropertyTabLayout() +void VPMainWindow::InitPropertyTabLayout() { // -------------------- init the unit combobox --------------------- ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm))); @@ -270,32 +277,32 @@ void PuzzleMainWindow::InitPropertyTabLayout() // see https://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect // -------------------- layout width, length, orientation ------------------------ - connect(ui->doubleSpinBoxLayoutWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::on_LayoutSizeChanged); - connect(ui->doubleSpinBoxLayoutLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::on_LayoutSizeChanged); - connect(ui->radioButtonLayoutPortrait, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::on_LayoutOrientationChanged); - connect(ui->radioButtonLayoutLandscape, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::on_LayoutOrientationChanged); + connect(ui->doubleSpinBoxSheetWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetSizeChanged); + connect(ui->doubleSpinBoxSheetLength, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetSizeChanged); + connect(ui->radioButtonSheetPortrait, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetOrientationChanged); + connect(ui->radioButtonSheetLandscape, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetOrientationChanged); // -------------------- margins ------------------------ - connect(ui->doubleSpinBoxLayoutMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::on_LayoutMarginChanged); - connect(ui->doubleSpinBoxLayoutMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::on_LayoutMarginChanged); - connect(ui->doubleSpinBoxLayoutMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::on_LayoutMarginChanged); - connect(ui->doubleSpinBoxLayoutMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &PuzzleMainWindow::on_LayoutMarginChanged); + connect(ui->doubleSpinBoxSheetMarginTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetMarginChanged); + connect(ui->doubleSpinBoxSheetMarginRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetMarginChanged); + connect(ui->doubleSpinBoxSheetMarginBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetMarginChanged); + connect(ui->doubleSpinBoxSheetMarginLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &VPMainWindow::on_SheetMarginChanged); // ------------------- follow grainline ----------------------- - connect(ui->radioButtonLayoutFollowGrainlineNo, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::on_LayoutFollowGrainlineChanged); - connect(ui->radioButtonLayoutFollowGrainlineVertical, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::on_LayoutFollowGrainlineChanged); - connect(ui->radioButtonLayoutFollowGrainlineHorizontal, QOverload::of(&QRadioButton::clicked), this, - &PuzzleMainWindow::on_LayoutFollowGrainlineChanged); + connect(ui->radioButtonSheetFollowGrainlineNo, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetFollowGrainlineChanged); + connect(ui->radioButtonSheetFollowGrainlineVertical, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetFollowGrainlineChanged); + connect(ui->radioButtonSheetFollowGrainlineHorizontal, QOverload::of(&QRadioButton::clicked), this, + &VPMainWindow::on_SheetFollowGrainlineChanged); // -------------------- export --------------------------- @@ -304,7 +311,7 @@ void PuzzleMainWindow::InitPropertyTabLayout() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::InitPropertyTabTiles() +void VPMainWindow::InitPropertyTabTiles() { // for the MVP we don't want the tiles tab. // we remove it. As soon as we need it, update this code @@ -312,26 +319,18 @@ void PuzzleMainWindow::InitPropertyTabTiles() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::InitPropertyTabLayers() +void VPMainWindow::InitCarrousel() { - // for the MVP we don't want the layers tab. - // we remove it. As soon as we need it, update this code - ui->tabWidgetProperties->removeTab(3); // remove layers -} + m_carrousel = new VPCarrousel(m_layout, ui->dockWidgetCarrousel); + ui->dockWidgetCarrousel->setWidget(m_carrousel); -//--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::InitPieceCarrousel() -{ - m_pieceCarrousel = new VPieceCarrousel(m_layout, ui->dockWidgetPieceCarrousel); - ui->dockWidgetPieceCarrousel->setWidget(m_pieceCarrousel); - - connect(ui->dockWidgetPieceCarrousel, QOverload::of(&QDockWidget::dockLocationChanged), this, - &PuzzleMainWindow::on_PieceCarrouselLocationChanged); + connect(ui->dockWidgetCarrousel, QOverload::of(&QDockWidget::dockLocationChanged), this, + &VPMainWindow::on_CarrouselLocationChanged); } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::SetPropertiesData() +void VPMainWindow::SetPropertiesData() { if(m_layout == nullptr) { @@ -340,14 +339,14 @@ void PuzzleMainWindow::SetPropertiesData() else { SetPropertyTabCurrentPieceData(); - SetPropertyTabLayoutData(); + SetPropertyTabSheetData(); SetPropertyTabTilesData(); - SetPropertyTabLayersData(); + SetPropertyTabLayoutData(); } } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::SetPropertyTabCurrentPieceData() +void VPMainWindow::SetPropertyTabCurrentPieceData() { if(m_selectedPieces.count() == 0) { @@ -364,7 +363,7 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData() ui->containerCurrentPieceData->setVisible(true); ui->containerCurrentPieceMultipleData->setVisible(false); - VPuzzlePiece *selectedPiece = m_selectedPieces.first(); + VPPiece *selectedPiece = m_selectedPieces.first(); // set the value to the current piece ui->lineEditCurrentPieceName->setText(selectedPiece->GetName()); @@ -394,8 +393,45 @@ void PuzzleMainWindow::SetPropertyTabCurrentPieceData() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::SetPropertyTabLayoutData() +void VPMainWindow::SetPropertyTabSheetData() { + // set name // TODO FIXME make it better + ui->lineEditSheetName->setText(m_layout->GetFocusedSheet()->GetName()); + + // set Width / Length + QSizeF size = m_layout->GetFocusedSheet()->GetSheetSizeConverted(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, size.width()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, size.height()); + + // Set Orientation + if(size.width() <= size.height()) + { + ui->radioButtonSheetPortrait->setChecked(true); + } + else + { + ui->radioButtonSheetLandscape->setChecked(true); + } + + // set margins + QMarginsF margins = m_layout->GetFocusedSheet()->GetSheetMarginsConverted(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginLeft, margins.left()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginTop, margins.top()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginRight, margins.right()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginBottom, margins.bottom()); + + // set pieces gap + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPiecesGap, m_layout->GetFocusedSheet()->GetPiecesGapConverted()); + + // set the checkboxes + SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->GetFocusedSheet()->GetStickyEdges()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::SetPropertyTabLayoutData() +{ + // TODO FIXME : Set name and description + // set Unit int index = ui->comboBoxLayoutUnit->findData(QVariant(UnitsToStr(m_layout->GetUnit()))); if(index != -1) @@ -405,53 +441,21 @@ void PuzzleMainWindow::SetPropertyTabLayoutData() ui->comboBoxLayoutUnit->blockSignals(false); } - // set Width / Length - QSizeF size = m_layout->GetLayoutSizeConverted(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, size.width()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, size.height()); - - // Set Orientation - if(size.width() <= size.height()) - { - ui->radioButtonLayoutPortrait->setChecked(true); - } - else - { - ui->radioButtonLayoutLandscape->setChecked(true); - } - - // set margins - QMarginsF margins = m_layout->GetLayoutMarginsConverted(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginLeft, margins.left()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginTop, margins.top()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginRight, margins.right()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutMarginBottom, margins.bottom()); - - // set pieces gap - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutPiecesGap, m_layout->GetPiecesGapConverted()); - - // set the checkboxes + // set controls SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesOutOfBound, m_layout->GetWarningPiecesOutOfBound()); SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces()); - SetCheckBoxValue(ui->checkBoxLayoutStickyEdges, m_layout->GetStickyEdges()); } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::SetPropertyTabTilesData() +void VPMainWindow::SetPropertyTabTilesData() { } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::SetPropertyTabLayersData() +void VPMainWindow::InitMainGraphics() { - -} - -//--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::InitMainGraphics() -{ - m_graphicsView = new VPuzzleMainGraphicsView(m_layout, this); + m_graphicsView = new VPMainGraphicsView(m_layout, this); ui->centralWidget->layout()->addWidget(m_graphicsView); m_graphicsView->RefreshLayout(); @@ -459,7 +463,7 @@ void PuzzleMainWindow::InitMainGraphics() //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal value) +void VPMainWindow::SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal value) { spinBox->blockSignals(true); spinBox->setValue(value); @@ -467,7 +471,7 @@ void PuzzleMainWindow::SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal valu } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::SetCheckBoxValue(QCheckBox *checkbox, bool value) +void VPMainWindow::SetCheckBoxValue(QCheckBox *checkbox, bool value) { checkbox->blockSignals(true); checkbox->setChecked(value); @@ -475,10 +479,10 @@ void PuzzleMainWindow::SetCheckBoxValue(QCheckBox *checkbox, bool value) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::ReadSettings() +void VPMainWindow::ReadSettings() { qCDebug(pWindow, "Reading settings."); - const VPuzzleSettings *settings = qApp->PuzzleSettings(); + const VPSettings *settings = qApp->PuzzleSettings(); if (settings->status() == QSettings::NoError) { @@ -502,9 +506,9 @@ void PuzzleMainWindow::ReadSettings() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::WriteSettings() +void VPMainWindow::WriteSettings() { - VPuzzleSettings *settings = qApp->PuzzleSettings(); + VPSettings *settings = qApp->PuzzleSettings(); settings->SetGeometry(saveGeometry()); settings->SetWindowState(saveState()); settings->SetToolbarsState(saveState(APP_VERSION)); @@ -520,7 +524,7 @@ void PuzzleMainWindow::WriteSettings() } //--------------------------------------------------------------------------------------------------------------------- -bool PuzzleMainWindow::MaybeSave() +bool VPMainWindow::MaybeSave() { // TODO: Implement maybe save check // if (this->isWindowModified()) @@ -568,11 +572,11 @@ bool PuzzleMainWindow::MaybeSave() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_actionNew_triggered() +void VPMainWindow::on_actionNew_triggered() { // just for test purpuses, to be removed: QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::New"); + msgBox.setText("TODO VPMainWindow::New"); int ret = msgBox.exec(); Q_UNUSED(ret); @@ -583,7 +587,7 @@ void PuzzleMainWindow::on_actionNew_triggered() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::closeEvent(QCloseEvent *event) +void VPMainWindow::closeEvent(QCloseEvent *event) { #if defined(Q_OS_MAC) && QT_VERSION < QT_VERSION_CHECK(5, 11, 1) // Workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-43344 @@ -607,7 +611,7 @@ void PuzzleMainWindow::closeEvent(QCloseEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_actionOpen_triggered() +void VPMainWindow::on_actionOpen_triggered() { qCDebug(pWindow, "Openning puzzle layout file."); @@ -661,11 +665,11 @@ void PuzzleMainWindow::on_actionOpen_triggered() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_actionSave_triggered() +void VPMainWindow::on_actionSave_triggered() { // just for test purpuses, to be removed: QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::Save"); + msgBox.setText("TODO VPMainWindow::Save"); int ret = msgBox.exec(); Q_UNUSED(ret); @@ -674,7 +678,7 @@ void PuzzleMainWindow::on_actionSave_triggered() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_actionSaveAs_triggered() +void VPMainWindow::on_actionSaveAs_triggered() { // TODO / FIXME : See valentina how the save is done over there. we need to add the extension .vlt, check for empty file names etc. @@ -704,7 +708,7 @@ void PuzzleMainWindow::on_actionSaveAs_triggered() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_actionImportRawLayout_triggered() +void VPMainWindow::on_actionImportRawLayout_triggered() { // TODO: here the code is probably just bad, to be edited @@ -733,11 +737,11 @@ void PuzzleMainWindow::on_actionImportRawLayout_triggered() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_actionCloseLayout_triggered() +void VPMainWindow::on_actionCloseLayout_triggered() { // just for test purpuses, to be removed: QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::CloseLayout"); + msgBox.setText("TODO VPMainWindow::CloseLayout"); int ret = msgBox.exec(); Q_UNUSED(ret); @@ -746,21 +750,21 @@ void PuzzleMainWindow::on_actionCloseLayout_triggered() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_actionAboutQt_triggered() +void VPMainWindow::on_actionAboutQt_triggered() { QMessageBox::aboutQt(this, tr("About Qt")); } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_actionAboutPuzzle_triggered() +void VPMainWindow::on_actionAboutPuzzle_triggered() { - auto *aboutDialog = new DialogAboutPuzzle(this); + auto *aboutDialog = new VPDialogAbout(this); aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true); aboutDialog->show(); } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) +void VPMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) { Q_UNUSED(index); QVariant comboBoxValue = ui->comboBoxLayoutUnit->currentData(); @@ -778,16 +782,16 @@ void PuzzleMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index) m_layout->SetUnit(Unit::Inch); } - SetPropertyTabLayoutData(); + SetPropertyTabSheetData(); SetPropertyTabCurrentPieceData(); } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_comboBoxLayoutTemplate_currentIndexChanged(int index) +void VPMainWindow::on_comboBoxSheetTemplate_currentIndexChanged(int index) { // just for test purpuses, to be removed: QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::LayoutTemplateChanged"); + msgBox.setText("TODO VPMainWindow::SheetTemplateChanged"); int ret = msgBox.exec(); Q_UNUSED(index); @@ -798,20 +802,20 @@ void PuzzleMainWindow::on_comboBoxLayoutTemplate_currentIndexChanged(int index) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_LayoutSizeChanged() +void VPMainWindow::on_SheetSizeChanged() { - m_layout->SetLayoutSizeConverted(ui->doubleSpinBoxLayoutWidth->value(), ui->doubleSpinBoxLayoutLength->value()); + m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value()); // updates orientation - no need to block signals because the signal reacts on "clicked" - if(ui->doubleSpinBoxLayoutWidth->value() <= ui->doubleSpinBoxLayoutLength->value()) + if(ui->doubleSpinBoxSheetWidth->value() <= ui->doubleSpinBoxSheetLength->value()) { //portrait - ui->radioButtonLayoutPortrait->setChecked(true); + ui->radioButtonSheetPortrait->setChecked(true); } else { //landscape - ui->radioButtonLayoutLandscape->setChecked(true); + ui->radioButtonSheetLandscape->setChecked(true); } // TODO Undo / Redo @@ -820,16 +824,16 @@ void PuzzleMainWindow::on_LayoutSizeChanged() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_LayoutOrientationChanged() +void VPMainWindow::on_SheetOrientationChanged() { // swap the width and length - qreal width_before = ui->doubleSpinBoxLayoutWidth->value(); - qreal length_before = ui->doubleSpinBoxLayoutLength->value(); + qreal width_before = ui->doubleSpinBoxSheetWidth->value(); + qreal length_before = ui->doubleSpinBoxSheetLength->value(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutWidth, length_before); - SetDoubleSpinBoxValue(ui->doubleSpinBoxLayoutLength, width_before); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, length_before); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, width_before); - m_layout->SetLayoutSizeConverted(ui->doubleSpinBoxLayoutWidth->value(), ui->doubleSpinBoxLayoutLength->value()); + m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value()); // TODO Undo / Redo @@ -837,11 +841,11 @@ void PuzzleMainWindow::on_LayoutOrientationChanged() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_pushButtonLayoutRemoveUnusedLength_clicked() +void VPMainWindow::on_pushButtonSheetRemoveUnusedLength_clicked() { // just for test purpuses, to be removed: QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::LayoutRemoveUnusedLength"); + msgBox.setText("TODO VPMainWindow::on_pushButtonSheetRemoveUnusedLength_clicked"); int ret = msgBox.exec(); Q_UNUSED(ret); @@ -851,13 +855,13 @@ void PuzzleMainWindow::on_pushButtonLayoutRemoveUnusedLength_clicked() //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_LayoutMarginChanged() +void VPMainWindow::on_SheetMarginChanged() { - m_layout->SetLayoutMarginsConverted( - ui->doubleSpinBoxLayoutMarginLeft->value(), - ui->doubleSpinBoxLayoutMarginTop->value(), - ui->doubleSpinBoxLayoutMarginRight->value(), - ui->doubleSpinBoxLayoutMarginBottom->value() + m_layout->GetFocusedSheet()->SetSheetMarginsConverted( + ui->doubleSpinBoxSheetMarginLeft->value(), + ui->doubleSpinBoxSheetMarginTop->value(), + ui->doubleSpinBoxSheetMarginRight->value(), + ui->doubleSpinBoxSheetMarginBottom->value() ); // TODO Undo / Redo @@ -867,11 +871,11 @@ void PuzzleMainWindow::on_LayoutMarginChanged() //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_LayoutFollowGrainlineChanged() +void VPMainWindow::on_SheetFollowGrainlineChanged() { // just for test purpuses, to be removed: QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::LayoutFollowGrainlineChanged"); + msgBox.setText("TODO VPMainWindow::on_SheetFollowGrainlineChanged"); int ret = msgBox.exec(); Q_UNUSED(ret); @@ -881,16 +885,16 @@ void PuzzleMainWindow::on_LayoutFollowGrainlineChanged() //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_doubleSpinBoxLayoutPiecesGap_valueChanged(double value) +void VPMainWindow::on_doubleSpinBoxSheetPiecesGap_valueChanged(double value) { - m_layout->SetPiecesGapConverted(value); + m_layout->GetFocusedSheet()->SetPiecesGapConverted(value); // TODO Undo / Redo // TODO update the QGraphicView } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_checkBoxLayoutWarningPiecesSuperposition_toggled(bool checked) +void VPMainWindow::on_checkBoxLayoutWarningPiecesSuperposition_toggled(bool checked) { m_layout->SetWarningSuperpositionOfPieces(checked); @@ -899,7 +903,7 @@ void PuzzleMainWindow::on_checkBoxLayoutWarningPiecesSuperposition_toggled(bool } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_checkBoxLayoutWarningPiecesOutOfBound_toggled(bool checked) +void VPMainWindow::on_checkBoxLayoutWarningPiecesOutOfBound_toggled(bool checked) { m_layout->SetWarningPiecesOutOfBound(checked); @@ -908,20 +912,20 @@ void PuzzleMainWindow::on_checkBoxLayoutWarningPiecesOutOfBound_toggled(bool che } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_checkBoxLayoutStickyEdges_toggled(bool checked) +void VPMainWindow::on_checkBoxSheetStickyEdges_toggled(bool checked) { - m_layout->SetStickyEdges(checked); + m_layout->GetFocusedSheet()->SetStickyEdges(checked); // TODO Undo / Redo // TODO update the QGraphicView } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_pushButtonLayoutExport_clicked() +void VPMainWindow::on_pushButtonSheetExport_clicked() { // just for test purpuses, to be removed: QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::LayoutExport"); + msgBox.setText("TODO VPMainWindow::on_pushButtonSheetExport_clicked"); int ret = msgBox.exec(); Q_UNUSED(ret); @@ -931,7 +935,7 @@ void PuzzleMainWindow::on_pushButtonLayoutExport_clicked() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_checkBoxCurrentPieceShowSeamline_toggled(bool checked) +void VPMainWindow::on_checkBoxCurrentPieceShowSeamline_toggled(bool checked) { if(m_selectedPieces.count() == 1) { @@ -940,7 +944,7 @@ void PuzzleMainWindow::on_checkBoxCurrentPieceShowSeamline_toggled(bool checked) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_checkBoxCurrentPieceMirrorPiece_toggled(bool checked) +void VPMainWindow::on_checkBoxCurrentPieceMirrorPiece_toggled(bool checked) { if(m_selectedPieces.count() == 1) { @@ -949,22 +953,22 @@ void PuzzleMainWindow::on_checkBoxCurrentPieceMirrorPiece_toggled(bool checked) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_doubleSpinBoxCurrentPieceAngle_valueChanged(double value) +void VPMainWindow::on_doubleSpinBoxCurrentPieceAngle_valueChanged(double value) { if(m_selectedPieces.count() == 1) { - VPuzzlePiece *piece = m_selectedPieces.first(); + VPPiece *piece = m_selectedPieces.first(); piece->SetRotation(value); } } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_CurrentPiecePositionEdited() +void VPMainWindow::on_CurrentPiecePositionEdited() { if(m_selectedPieces.count() == 1) { - VPuzzlePiece *piece = m_selectedPieces.first(); + VPPiece *piece = m_selectedPieces.first(); QPointF pos(UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionX->value(), m_layout->GetUnit(), Unit::Px), UnitConvertor(ui->doubleSpinBoxCurrentPieceBoxPositionY->value(), m_layout->GetUnit(), Unit::Px)); piece->SetPosition(pos); @@ -972,20 +976,20 @@ void PuzzleMainWindow::on_CurrentPiecePositionEdited() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area) +void VPMainWindow::on_CarrouselLocationChanged(Qt::DockWidgetArea area) { if(area == Qt::BottomDockWidgetArea || area == Qt::TopDockWidgetArea) { - m_pieceCarrousel->SetOrientation(Qt::Horizontal); + m_carrousel->SetOrientation(Qt::Horizontal); } else if (area == Qt::LeftDockWidgetArea || area == Qt::RightDockWidgetArea) { - m_pieceCarrousel->SetOrientation(Qt::Vertical); + m_carrousel->SetOrientation(Qt::Vertical); } } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_PieceSelectionChanged() +void VPMainWindow::on_PieceSelectionChanged() { m_selectedPieces = m_layout->GetSelectedPieces(); @@ -995,11 +999,11 @@ void PuzzleMainWindow::on_PieceSelectionChanged() //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_PiecePositionChanged() +void VPMainWindow::on_PiecePositionChanged() { if(m_selectedPieces.count() == 1) { - VPuzzlePiece *piece = m_selectedPieces.first(); + VPPiece *piece = m_selectedPieces.first(); QPointF pos = piece->GetPosition(); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceBoxPositionX, @@ -1010,11 +1014,11 @@ void PuzzleMainWindow::on_PiecePositionChanged() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzleMainWindow::on_PieceRotationChanged() +void VPMainWindow::on_PieceRotationChanged() { if(m_selectedPieces.count() == 1) { - VPuzzlePiece *piece = m_selectedPieces.first(); + VPPiece *piece = m_selectedPieces.first(); qreal angle = piece->GetRotation(); SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceAngle, angle); diff --git a/src/app/puzzle/puzzlemainwindow.h b/src/app/puzzle/vpmainwindow.h similarity index 84% rename from src/app/puzzle/puzzlemainwindow.h rename to src/app/puzzle/vpmainwindow.h index 00abf3c7f..65380c4dc 100644 --- a/src/app/puzzle/puzzlemainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file puzzlemainwindow.h + ** @file vpmainwindow.h ** @author Roman Telezhynskyi ** @date 16 2, 2020 ** @@ -25,33 +25,33 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#ifndef PUZZLEMAINWINDOW_H -#define PUZZLEMAINWINDOW_H +#ifndef VPMAINWINDOW_H +#define VPMAINWINDOW_H #include #include #include #include "../vmisc/def.h" -#include "vpiececarrousel.h" -#include "vpuzzlemaingraphicsview.h" -#include "vpuzzlelayout.h" -#include "vpuzzlepiece.h" +#include "vpcarrousel.h" +#include "vpmaingraphicsview.h" +#include "vplayout.h" +#include "vppiece.h" #include "../vlayout/vlayoutpiece.h" -#include "vpuzzlecommandline.h" +#include "vpcommandline.h" namespace Ui { - class PuzzleMainWindow; + class VPMainWindow; } -class PuzzleMainWindow : public QMainWindow +class VPMainWindow : public QMainWindow { Q_OBJECT public: - explicit PuzzleMainWindow(const VPuzzleCommandLinePtr &cmd, QWidget *parent = nullptr); - virtual ~PuzzleMainWindow(); + explicit VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent = nullptr); + virtual ~VPMainWindow(); /** * @brief LoadFile Loads the layout file of given path in m_layout. @@ -87,22 +87,22 @@ protected: virtual void closeEvent(QCloseEvent *event) override; private: - Q_DISABLE_COPY(PuzzleMainWindow) - Ui::PuzzleMainWindow *ui; + Q_DISABLE_COPY(VPMainWindow) + Ui::VPMainWindow *ui; - VPieceCarrousel *m_pieceCarrousel{nullptr}; - VPuzzleMainGraphicsView *m_graphicsView{nullptr}; + VPCarrousel *m_carrousel{nullptr}; + VPMainGraphicsView *m_graphicsView{nullptr}; - VPuzzleCommandLinePtr m_cmd; + VPCommandLinePtr m_cmd; - VPuzzleLayout *m_layout{nullptr}; - QListm_selectedPieces{QList()}; + VPLayout *m_layout{nullptr}; + QListm_selectedPieces{QList()}; /** * @brief CreatePiece creates a piece from the given VLayoutPiece data * @param rawPiece the raw piece data */ - VPuzzlePiece* CreatePiece(const VLayoutPiece &rawPiece); + VPPiece* CreatePiece(const VLayoutPiece &rawPiece); /** * @brief InitMenuBar Inits the menu bar (File, Edit, Help ...) @@ -130,14 +130,9 @@ private: void InitPropertyTabTiles(); /** - * @brief InitPropertyTabLayers Inits the layers tab in the properties + * @brief InitCarrousel Inits the carrousel */ - void InitPropertyTabLayers(); - - /** - * @brief InitPieceCarrousel Inits the piece carrousel - */ - void InitPieceCarrousel(); + void InitCarrousel(); /** * @brief InitMainGraphics Initialises the puzzle main graphics @@ -157,10 +152,10 @@ private: void SetPropertyTabCurrentPieceData(); /** - * @brief SetPropertyTabLayoutData Sets the values of UI elements - * in the Layout Tab to the values saved in m_layout + * @brief SetPropertyTabSheetData Sets the values of UI elements + * in the Sheet Tab to the values saved in focused sheet */ - void SetPropertyTabLayoutData(); + void SetPropertyTabSheetData(); /** * @brief SetPropertyTabTilesData Sets the values of UI elements @@ -169,10 +164,10 @@ private: void SetPropertyTabTilesData(); /** - * @brief SetPropertyTabLayersData Sets the values of UI elements - * in the Layers Tab to the values saved in m_layout - */ - void SetPropertyTabLayersData(); + * @brief SetPropertyTabLayoutData Sets the values of UI elements + * in the Layout Tab to the values saved in m_layout + */ + void SetPropertyTabLayoutData(); /** * @brief SetDoubleSpinBoxValue sets the given spinbox to the given value. @@ -259,38 +254,38 @@ private slots: * The slot is automatically connected through name convention. * @param index the index of the selected templated */ - void on_comboBoxLayoutTemplate_currentIndexChanged(int index); + void on_comboBoxSheetTemplate_currentIndexChanged(int index); /** * @brief LayoutSizeChanged When the width or the length has been changed in * the layout property tab */ - void on_LayoutSizeChanged(); + void on_SheetSizeChanged(); /** * @brief LayoutOrientationChanged When one of the radio boxes for the layout * orientation has been clicked */ - void on_LayoutOrientationChanged(); + void on_SheetOrientationChanged(); /** * @brief on_pushButtonLayoutRemoveUnusedLength_clicked When the button * "Remove unused length" in the layout property tab is clicked. * The slot is automatically connected through name convention. */ - void on_pushButtonLayoutRemoveUnusedLength_clicked(); + void on_pushButtonSheetRemoveUnusedLength_clicked(); /** * @brief on_LayoutMarginChanged When one of the margin values has been changed * in the layout property tab. */ - void on_LayoutMarginChanged(); + void on_SheetMarginChanged(); /** * @brief LayoutFollowGrainlineChanged When one of the radio boxes for the * "Follow grainline" has been clicked in the layout property tab. */ - void on_LayoutFollowGrainlineChanged(); + void on_SheetFollowGrainlineChanged(); /** * @brief on_doubleSpinBoxLayoutPiecesGap_valueChanged When the "pieces gap" @@ -298,7 +293,7 @@ private slots: * The slot is automatically connected through name convention. * @param value the new value of the pieces gap */ - void on_doubleSpinBoxLayoutPiecesGap_valueChanged(double value); + void on_doubleSpinBoxSheetPiecesGap_valueChanged(double value); /** * @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the @@ -324,14 +319,14 @@ private slots: * The slot is automatically connected through name convention. * @param checked the new checked value */ - void on_checkBoxLayoutStickyEdges_toggled(bool checked); + void on_checkBoxSheetStickyEdges_toggled(bool checked); /** * @brief on_pushButtonLayoutExport_clicked When the button * "Export layout" in the layout property is clicked. * The slot is automatically connected through name convention. */ - void on_pushButtonLayoutExport_clicked(); + void on_pushButtonSheetExport_clicked(); /** * @brief on_checkBoxCurrentPieceShowSeamline_toggled When the @@ -364,11 +359,11 @@ private slots: void on_CurrentPiecePositionEdited(); /** - * @brief PieceCarrouselLocationChanged When the piece carrousel's location + * @brief CarrouselLocationChanged When the piece carrousel's location * has been changed * @param area The new area where the piece carrousel has been placed */ - void on_PieceCarrouselLocationChanged(Qt::DockWidgetArea area); + void on_CarrouselLocationChanged(Qt::DockWidgetArea area); /** * @brief on_PieceSelectionChanged When the piece selection has changed @@ -387,4 +382,4 @@ private slots: }; -#endif // PUZZLEMAINWINDOW_H +#endif // VPMAINWINDOW_H diff --git a/src/app/puzzle/puzzlemainwindow.ui b/src/app/puzzle/vpmainwindow.ui similarity index 84% rename from src/app/puzzle/puzzlemainwindow.ui rename to src/app/puzzle/vpmainwindow.ui index 79ed17157..461e49af9 100644 --- a/src/app/puzzle/puzzlemainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -1,7 +1,7 @@ - PuzzleMainWindow - + VPMainWindow + 0 @@ -82,7 +82,7 @@ - + 0 @@ -110,7 +110,7 @@ 1 - + 0 @@ -230,7 +230,7 @@ 0 0 342 - 1318 + 1264 @@ -253,6 +253,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + @@ -398,6 +410,18 @@ 0 + + 0 + + + 0 + + + 0 + + + 0 + @@ -420,6 +444,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + @@ -458,7 +494,7 @@ - + :/puzzleicon/64x64/iconLayout.png:/puzzleicon/64x64/iconLayout.png @@ -483,7 +519,7 @@ 0 - + QFrame::NoFrame @@ -507,12 +543,12 @@ - + font-weight: bold; - Layout + Current sheet Qt::AlignCenter @@ -520,7 +556,30 @@ - + + + Infos + + + + + + + + Name + + + + + + + + + + + + + Format @@ -528,64 +587,54 @@ - - - Unit - - - - - - - - + Template - - + + - - + + Width - - + + 100000.000000000000000 - - + + + + Length + + + + + 100000.000000000000000 - - - Length - - - - - + Orientation - + - + Portrait @@ -608,7 +657,7 @@ - + Landscape @@ -632,7 +681,7 @@ - + Remove unused length @@ -642,13 +691,13 @@ - + Margins - + Right: @@ -658,7 +707,7 @@ - + Top: @@ -668,21 +717,21 @@ - + 0.100000000000000 - + 0.100000000000000 - + Left: @@ -692,7 +741,7 @@ - + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -702,14 +751,14 @@ - + 0.100000000000000 - + Bottom: @@ -722,7 +771,7 @@ - + Control @@ -730,7 +779,7 @@ - + Follow grainline @@ -739,7 +788,7 @@ - + No @@ -749,7 +798,7 @@ - + Vertical grainline @@ -769,7 +818,7 @@ - + Horizontal grainline @@ -791,33 +840,19 @@ - + Pieces gap - + - - - Warning superposition of pieces - - - - - - - Warning pieces out of bound - - - - - + Sticky edges @@ -827,7 +862,7 @@ - + Export @@ -835,21 +870,21 @@ - + Format - + - + - Export Layout + Export Sheet @@ -857,7 +892,7 @@ - + Qt::Vertical @@ -929,7 +964,7 @@ font-weight: bold; - Tiles + Tiles of current sheet Qt::AlignCenter @@ -955,18 +990,11 @@ - - - - :/puzzleicon/64x64/iconLayers.png:/puzzleicon/64x64/iconLayers.png - + - + Prop. - - Layers properties - - + 0 @@ -980,7 +1008,7 @@ 0 - + QFrame::NoFrame @@ -993,7 +1021,7 @@ true - + 0 @@ -1004,12 +1032,12 @@ - + - font-weight:bold; + font-weight: bold; - Layers + Layout Qt::AlignCenter @@ -1017,7 +1045,90 @@ - + + + Infos + + + + + + + + Name + + + + + + + My layout + + + + + + + + + Description + + + + + + + + + + + + + Format + + + + + + + + Unit + + + + + + + + + + + + + + + Control + + + + + + Warning superposition of pieces + + + + + + + Warning pieces out of bound + + + + + + + + Qt::Vertical @@ -1121,12 +1232,11 @@ - scrollAreaLayout - doubleSpinBoxLayoutMarginTop - doubleSpinBoxLayoutMarginLeft - doubleSpinBoxLayoutMarginRight - doubleSpinBoxLayoutMarginBottom - scrollAreaLayers + scrollAreaSheet + doubleSpinBoxSheetMarginTop + doubleSpinBoxSheetMarginLeft + doubleSpinBoxSheetMarginRight + doubleSpinBoxSheetMarginBottom scrollAreaTiles diff --git a/src/app/puzzle/vpuzzlemimedatapiece.cpp b/src/app/puzzle/vpmimedatapiece.cpp similarity index 85% rename from src/app/puzzle/vpuzzlemimedatapiece.cpp rename to src/app/puzzle/vpmimedatapiece.cpp index 873d500c8..a92f724e5 100644 --- a/src/app/puzzle/vpuzzlemimedatapiece.cpp +++ b/src/app/puzzle/vpmimedatapiece.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlemimedatapiece.cpp + ** @file vpmimedatapiece.cpp ** @author Ronan Le Tiec ** @date 4 5, 2020 ** @@ -26,28 +26,28 @@ ** *************************************************************************/ -#include "vpuzzlemimedatapiece.h" +#include "vpmimedatapiece.h" //--------------------------------------------------------------------------------------------------------------------- -VPuzzleMimeDataPiece::VPuzzleMimeDataPiece() +VPMimeDataPiece::VPMimeDataPiece() { } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleMimeDataPiece::~VPuzzleMimeDataPiece() +VPMimeDataPiece::~VPMimeDataPiece() { } //--------------------------------------------------------------------------------------------------------------------- -VPuzzlePiece* VPuzzleMimeDataPiece::GetPiecePtr() const +VPPiece* VPMimeDataPiece::GetPiecePtr() const { return m_piece; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleMimeDataPiece::SetPiecePtr(VPuzzlePiece* piece) +void VPMimeDataPiece::SetPiecePtr(VPPiece* piece) { m_piece = piece; } diff --git a/src/app/puzzle/vpuzzlemimedatapiece.h b/src/app/puzzle/vpmimedatapiece.h similarity index 77% rename from src/app/puzzle/vpuzzlemimedatapiece.h rename to src/app/puzzle/vpmimedatapiece.h index 8246c604b..cb5ba0ca7 100644 --- a/src/app/puzzle/vpuzzlemimedatapiece.h +++ b/src/app/puzzle/vpmimedatapiece.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlemimedatapiece.h + ** @file vpmimedatapiece.h ** @author Ronan Le Tiec ** @date 4 5, 2020 ** @@ -26,40 +26,40 @@ ** *************************************************************************/ -#ifndef VPUZZLEMIMEDATAPIECE_H -#define VPUZZLEMIMEDATAPIECE_H +#ifndef VPMIMEDATAPIECE_H +#define VPMIMEDATAPIECE_H #include -#include "vpuzzlepiece.h" +#include "vppiece.h" -class VPuzzleMimeDataPiece : public QMimeData +class VPMimeDataPiece : public QMimeData { Q_OBJECT public: - VPuzzleMimeDataPiece(); - ~VPuzzleMimeDataPiece(); + VPMimeDataPiece(); + ~VPMimeDataPiece(); /** * @brief GetPiecePtr Returns the piece pointer of the mime data * @return piece pointer */ - VPuzzlePiece* GetPiecePtr() const; + VPPiece* GetPiecePtr() const; /** * @brief SetPiecePtr sets the piece pointer to the given value * @param piece the piece pointer */ - void SetPiecePtr(VPuzzlePiece* piece); + void SetPiecePtr(VPPiece* piece); private: - Q_DISABLE_COPY(VPuzzleMimeDataPiece) + Q_DISABLE_COPY(VPMimeDataPiece) - VPuzzlePiece *m_piece{nullptr}; + VPPiece *m_piece{nullptr}; }; -#endif // VPUZZLEMIMEDATAPIECE_H +#endif // VPMIMEDATAPIECE_H diff --git a/src/app/puzzle/vpuzzlepiece.cpp b/src/app/puzzle/vppiece.cpp similarity index 70% rename from src/app/puzzle/vpuzzlepiece.cpp rename to src/app/puzzle/vppiece.cpp index dc11f77ca..ed3df5899 100644 --- a/src/app/puzzle/vpuzzlepiece.cpp +++ b/src/app/puzzle/vppiece.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlepiece.cpp + ** @file vppiece.cpp ** @author Ronan Le Tiec ** @date 13 4, 2020 ** @@ -25,11 +25,11 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#include "vpuzzlepiece.h" +#include "vppiece.h" #include -#include "vpuzzlelayer.h" +#include "vppiecelist.h" #include "../vmisc/def.h" #include @@ -39,77 +39,77 @@ Q_LOGGING_CATEGORY(pPiece, "p.piece") //--------------------------------------------------------------------------------------------------------------------- -VPuzzlePiece::VPuzzlePiece() +VPPiece::VPPiece() { } //--------------------------------------------------------------------------------------------------------------------- -VPuzzlePiece::~VPuzzlePiece() +VPPiece::~VPPiece() { } //--------------------------------------------------------------------------------------------------------------------- -QString VPuzzlePiece::GetName() const +QString VPPiece::GetName() const { return m_name; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetName(const QString &name) +void VPPiece::SetName(const QString &name) { m_name = name; } //--------------------------------------------------------------------------------------------------------------------- -QUuid VPuzzlePiece::GetUuid() const +QUuid VPPiece::GetUuid() const { return m_uuid; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetUuid(const QUuid &uuid) +void VPPiece::SetUuid(const QUuid &uuid) { m_uuid = uuid; } //--------------------------------------------------------------------------------------------------------------------- -QVector VPuzzlePiece::GetCuttingLine() const +QVector VPPiece::GetCuttingLine() const { return m_cuttingLine; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetCuttingLine(const QVector &cuttingLine) +void VPPiece::SetCuttingLine(const QVector &cuttingLine) { m_cuttingLine = cuttingLine; } //--------------------------------------------------------------------------------------------------------------------- -QVector VPuzzlePiece::GetSeamLine() const +QVector VPPiece::GetSeamLine() const { return m_seamLine; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetSeamLine(const QVector &seamLine) +void VPPiece::SetSeamLine(const QVector &seamLine) { m_seamLine = seamLine; } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzlePiece::GetShowSeamLine() const +bool VPPiece::GetShowSeamLine() const { return m_showSeamline; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetShowSeamLine(bool value) +void VPPiece::SetShowSeamLine(bool value) { m_showSeamline = value; @@ -117,13 +117,13 @@ void VPuzzlePiece::SetShowSeamLine(bool value) } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzlePiece::GetPieceMirrored() const +bool VPPiece::GetPieceMirrored() const { return m_mirrorPiece; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetPieceMirrored(bool value) +void VPPiece::SetPieceMirrored(bool value) { m_mirrorPiece = value; @@ -131,7 +131,7 @@ void VPuzzlePiece::SetPieceMirrored(bool value) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetPosition(QPointF point) +void VPPiece::SetPosition(QPointF point) { m_transform.translate(point.x() - m_transform.dx(), point.y() - m_transform.dy()); @@ -139,13 +139,13 @@ void VPuzzlePiece::SetPosition(QPointF point) } //--------------------------------------------------------------------------------------------------------------------- -QPointF VPuzzlePiece::GetPosition() +QPointF VPPiece::GetPosition() { return QPointF(m_transform.dx(), m_transform.dy()); } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetRotation(qreal angle) +void VPPiece::SetRotation(qreal angle) { // qreal currentAngle = GetRotation(); // qreal newAngle = angle - currentAngle; @@ -172,7 +172,7 @@ void VPuzzlePiece::SetRotation(qreal angle) } //--------------------------------------------------------------------------------------------------------------------- -qreal VPuzzlePiece::GetRotation() +qreal VPPiece::GetRotation() { return m_pieceAngle; @@ -191,7 +191,7 @@ qreal VPuzzlePiece::GetRotation() } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetIsSelected(bool value) +void VPPiece::SetIsSelected(bool value) { if(m_isSelected != value) { @@ -201,100 +201,59 @@ void VPuzzlePiece::SetIsSelected(bool value) } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzlePiece::GetIsSelected() +bool VPPiece::GetIsSelected() { return m_isSelected; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetIsGrainlineEnabled(bool value) +void VPPiece::SetIsGrainlineEnabled(bool value) { m_isGrainlineEnabled = value; } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzlePiece::GetIsGrainlineEnabled() +bool VPPiece::GetIsGrainlineEnabled() { return m_isGrainlineEnabled; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetGrainlineAngle(qreal value) +void VPPiece::SetGrainlineAngle(qreal value) { m_grainlineAngle = value; } //--------------------------------------------------------------------------------------------------------------------- -qreal VPuzzlePiece::GetGrainlineAngle() +qreal VPPiece::GetGrainlineAngle() { return m_grainlineAngle; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetGrainline(QVector grainline) +void VPPiece::SetGrainline(QVector grainline) { m_grainline = grainline; } //--------------------------------------------------------------------------------------------------------------------- -QVector VPuzzlePiece::GetGrainline() +QVector VPPiece::GetGrainline() { return m_grainline; } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayer* VPuzzlePiece::GetLayer() +VPPieceList* VPPiece::GetPieceList() { - return m_layer; + return m_pieceList; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzlePiece::SetLayer(VPuzzleLayer* layer) +void VPPiece::SetPieceList(VPPieceList* pieceList) { - if(layer != m_layer) + if(pieceList != m_pieceList) { - m_layer = layer; + m_pieceList = pieceList; } } -//--------------------------------------------------------------------------------------------------------------------- -QIcon VPuzzlePiece::PieceIcon(const QSize &size) const -{ - QVector points = GetSeamLine(); - if(points.isEmpty()) - { - points = GetCuttingLine(); - } - QPolygonF shape(points); - shape << shape.first(); - - QRectF boundingRect = shape.boundingRect(); - qreal canvasSize = qMax(boundingRect.height(), boundingRect.width()); - QRectF canvas = QRectF(0, 0, canvasSize, canvasSize); - - qreal dx = canvas.center().x() - boundingRect.center().x(); - qreal dy = canvas.center().y() - boundingRect.center().y(); - - QPixmap pixmap(size); - pixmap.fill(QColor("white")); - - QPainter painter; - painter.begin(&pixmap); - painter.setRenderHint(QPainter::Antialiasing); - painter.setRenderHint(QPainter::SmoothPixmapTransform); - - int spacing = 2; - painter.translate(spacing, spacing); - - qreal scaleFactorX = canvasSize * 100 / (size.width() - spacing*2) / 100; - qreal scaleFactorY = canvasSize * 100 / (size.height() - spacing*2) / 100; - painter.scale(1./scaleFactorX, 1./scaleFactorY); - painter.setPen(QPen(Qt::black, 0.8*qMax(scaleFactorX, scaleFactorY))); - - painter.translate(dx, dy); - - painter.drawPolygon(shape); - painter.end(); - - return QIcon(pixmap); -} diff --git a/src/app/puzzle/vpuzzlepiece.h b/src/app/puzzle/vppiece.h similarity index 92% rename from src/app/puzzle/vpuzzlepiece.h rename to src/app/puzzle/vppiece.h index c859de99e..d536c569f 100644 --- a/src/app/puzzle/vpuzzlepiece.h +++ b/src/app/puzzle/vppiece.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlepiece.h + ** @file vppiece.h ** @author Ronan Le Tiec ** @date 13 4, 2020 ** @@ -25,22 +25,22 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#ifndef VPUZZLEPIECE_H -#define VPUZZLEPIECE_H +#ifndef VPPIECE_H +#define VPPIECE_H #include #include #include #include -class VPuzzleLayer; +class VPPieceList; -class VPuzzlePiece : public QObject +class VPPiece : public QObject { Q_OBJECT public: - VPuzzlePiece(); - ~VPuzzlePiece(); + VPPiece(); + ~VPPiece(); /** * @brief GetName Returns the name of the piece @@ -187,16 +187,16 @@ public: bool GetIsSelected(); /** - * @brief GetLayer Returns the layer in which the piece is. - * @return layer of the piece + * @brief GetPieceList Returns the piecelist in which the piece is. + * @return pieceList of the piece */ - VPuzzleLayer* GetLayer(); + VPPieceList* GetPieceList(); /** - * @brief SetLayer Sets the layer of the piece to the given layer - * @param layer + * @brief SetPieceList Sets the pieceList of the piece to the given pieceList + * @param pieceList */ - void SetLayer(VPuzzleLayer* layer); + void SetPieceList(VPPieceList* pieceList); QIcon PieceIcon(const QSize &size) const; @@ -226,7 +226,7 @@ signals: void PropertiesChanged(); private: - Q_DISABLE_COPY(VPuzzlePiece) + Q_DISABLE_COPY(VPPiece) QUuid m_uuid{QUuid()}; QString m_name{QString()}; QVector m_cuttingLine{QVector()}; @@ -244,7 +244,7 @@ private: bool m_mirrorPiece{false}; bool m_isSelected{false}; - VPuzzleLayer *m_layer{nullptr}; + VPPieceList *m_pieceList{nullptr}; }; -#endif // VPUZZLEPIECE_H +#endif // VPPIECE_H diff --git a/src/app/puzzle/vpuzzlelayer.cpp b/src/app/puzzle/vppiecelist.cpp similarity index 75% rename from src/app/puzzle/vpuzzlelayer.cpp rename to src/app/puzzle/vppiecelist.cpp index efe1ce0dd..65606f83c 100644 --- a/src/app/puzzle/vpuzzlelayer.cpp +++ b/src/app/puzzle/vppiecelist.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlelayer.cpp + ** @file vppiecelist.cpp ** @author Ronan Le Tiec ** @date 13 4, 2020 ** @@ -25,42 +25,49 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#include "vpuzzlelayer.h" +#include "vppiecelist.h" -#include "vpuzzlelayout.h" +#include "vplayout.h" #include -Q_LOGGING_CATEGORY(pLayer, "p.layer") +Q_LOGGING_CATEGORY(pPieceList, "p.pieceList") //--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayer::VPuzzleLayer(VPuzzleLayout *layout): +VPPieceList::VPPieceList(VPLayout *layout, VPSheet *sheet): + m_sheet(sheet), m_layout(layout) { } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayer::~VPuzzleLayer() +VPPieceList::~VPPieceList() { } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayout* VPuzzleLayer::GetLayout() +VPLayout* VPPieceList::GetLayout() { return m_layout; } //--------------------------------------------------------------------------------------------------------------------- -QList VPuzzleLayer::GetPieces() +VPSheet* VPPieceList::GetSheet() +{ + return m_sheet; +} + +//--------------------------------------------------------------------------------------------------------------------- +QList VPPieceList::GetPieces() { return m_pieces; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayer::ClearSelection() +void VPPieceList::ClearSelection() { for (auto piece: m_pieces) { @@ -69,45 +76,45 @@ void VPuzzleLayer::ClearSelection() } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayer::AddPiece(VPuzzlePiece *piece) +void VPPieceList::AddPiece(VPPiece *piece) { - qCDebug(pLayer(), "piece -- %s -- added to %s", qUtf8Printable(piece->GetName()), qUtf8Printable(this->GetName())); + qCDebug(pPieceList(), "piece -- %s -- added to %s", qUtf8Printable(piece->GetName()), qUtf8Printable(this->GetName())); m_pieces.append(piece); - piece->SetLayer(this); + piece->SetPieceList(this); emit PieceAdded(piece); } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayer::RemovePiece(VPuzzlePiece *piece) +void VPPieceList::RemovePiece(VPPiece *piece) { m_pieces.removeAll(piece); - piece->SetLayer(nullptr); + piece->SetPieceList(nullptr); emit PieceRemoved(piece); } //--------------------------------------------------------------------------------------------------------------------- -QString VPuzzleLayer::GetName() const +QString VPPieceList::GetName() const { return m_name; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayer::SetName(const QString &name) +void VPPieceList::SetName(const QString &name) { m_name = name; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayer::SetIsVisible(bool value) +void VPPieceList::SetIsVisible(bool value) { m_isVisible = value; } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleLayer::GetIsVisible() const +bool VPPieceList::GetIsVisible() const { return m_isVisible; } diff --git a/src/app/puzzle/vpuzzlelayer.h b/src/app/puzzle/vppiecelist.h similarity index 66% rename from src/app/puzzle/vpuzzlelayer.h rename to src/app/puzzle/vppiecelist.h index 435701eff..c0e86b6fd 100644 --- a/src/app/puzzle/vpuzzlelayer.h +++ b/src/app/puzzle/vppiecelist.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlelayer.h + ** @file vppiecelist.h ** @author Ronan Le Tiec ** @date 13 4, 2020 ** @@ -25,24 +25,25 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#ifndef VPUZZLELAYER_H -#define VPUZZLELAYER_H +#ifndef VPPIECELIST_H +#define VPPIECELIST_H #include -#include "vpuzzlepiece.h" +#include "vppiece.h" +#include "vpsheet.h" -class VPuzzleLayout; +class VPLayout; -class VPuzzleLayer : public QObject +class VPPieceList : public QObject { Q_OBJECT public: - VPuzzleLayer(VPuzzleLayout *layout); - ~VPuzzleLayer(); + VPPieceList(VPLayout *layout, VPSheet *sheet = nullptr); + ~VPPieceList(); - QList GetPieces(); - void AddPiece(VPuzzlePiece *piece); - void RemovePiece(VPuzzlePiece *piece); + QList GetPieces(); + void AddPiece(VPPiece *piece); + void RemovePiece(VPPiece *piece); // here add some more function if we want to add/move a piece at a // certain position in the list @@ -54,13 +55,21 @@ public: bool GetIsVisible() const; /** - * @brief GetLayout Returns the layout in which this layer is - * @return the layout of this layer + * @brief GetLayout Returns the layout in which this piece list is + * @return the layout of this piece list */ - VPuzzleLayout* GetLayout(); + VPLayout* GetLayout(); + /** - * @brief ClearSelection Clears the selection of the pieces in this layer + * @brief GetSheet returns the sheet corresponding to this piece list, or nullptr + * if no sheet associated + * @return the sheet + */ + VPSheet* GetSheet(); + + /** + * @brief ClearSelection Clears the selection of the pieces in this piece list */ void ClearSelection(); @@ -68,24 +77,26 @@ signals: /** * @brief PieceAdded The signal is emited when a piece was added */ - void PieceAdded(VPuzzlePiece *piece); + void PieceAdded(VPPiece *piece); /** * @brief PieceRemoved The signal is emited when a piece was removed */ - void PieceRemoved(VPuzzlePiece *piece); + void PieceRemoved(VPPiece *piece); private: - Q_DISABLE_COPY(VPuzzleLayer) + Q_DISABLE_COPY(VPPieceList) QString m_name{}; - QList m_pieces{}; + QList m_pieces{}; - VPuzzleLayout *m_layout{nullptr}; + VPSheet *m_sheet{nullptr}; + + VPLayout *m_layout{nullptr}; // control bool m_isVisible{true}; }; -#endif // VPUZZLELAYER_H +#endif // VPPIECELIST_H diff --git a/src/app/puzzle/vpuzzlesettings.cpp b/src/app/puzzle/vpsettings.cpp similarity index 81% rename from src/app/puzzle/vpuzzlesettings.cpp rename to src/app/puzzle/vpsettings.cpp index 6d4ad24d0..4d7360762 100644 --- a/src/app/puzzle/vpuzzlesettings.cpp +++ b/src/app/puzzle/vpsettings.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlesettings.cpp + ** @file vpsettings.cpp ** @author Roman Telezhynskyi ** @date 16 2, 2020 ** @@ -25,7 +25,7 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#include "vpuzzlesettings.h" +#include "vpsettings.h" namespace { @@ -34,48 +34,48 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockPropertiesContentsActive, (Q } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleSettings::VPuzzleSettings(Format format, Scope scope, const QString &organization, const QString &application, +VPSettings::VPSettings(Format format, Scope scope, const QString &organization, const QString &application, QObject *parent) : VCommonSettings(format, scope, organization, application, parent) {} //--------------------------------------------------------------------------------------------------------------------- -VPuzzleSettings::VPuzzleSettings(const QString &fileName, QSettings::Format format, QObject *parent) +VPSettings::VPSettings(const QString &fileName, QSettings::Format format, QObject *parent) : VCommonSettings(fileName, format, parent) {} //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleSettings::IsDockWidgetPropertiesActive() const +bool VPSettings::IsDockWidgetPropertiesActive() const { return value(*settingDockWidgetPropertiesActive, GetDefDockWidgetPropertiesActive()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleSettings::GetDefDockWidgetPropertiesActive() +bool VPSettings::GetDefDockWidgetPropertiesActive() { return true; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleSettings::SetDockWidgetPropertiesActive(bool value) +void VPSettings::SetDockWidgetPropertiesActive(bool value) { setValue(*settingDockWidgetPropertiesActive, value); } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleSettings::IsDockWidgetPropertiesContentsActive() const +bool VPSettings::IsDockWidgetPropertiesContentsActive() const { return value(*settingDockWidgetPropertiesActive, GetDefDockWidgetPropertiesActive()).toBool(); } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleSettings::GetDefDockWidgetPropertiesContentsActive() +bool VPSettings::GetDefDockWidgetPropertiesContentsActive() { return true; } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleSettings::SetDockWidgetPropertiesContentsActive(bool value) +void VPSettings::SetDockWidgetPropertiesContentsActive(bool value) { setValue(*settingDockPropertiesContentsActive, value); } diff --git a/src/app/puzzle/vpuzzlesettings.h b/src/app/puzzle/vpsettings.h similarity index 80% rename from src/app/puzzle/vpuzzlesettings.h rename to src/app/puzzle/vpsettings.h index 97906df41..6d822042d 100644 --- a/src/app/puzzle/vpuzzlesettings.h +++ b/src/app/puzzle/vpsettings.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlesettings.h + ** @file vpsettings.h ** @author Roman Telezhynskyi ** @date 16 2, 2020 ** @@ -25,20 +25,20 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#ifndef VPUZZLESETTINGS_H -#define VPUZZLESETTINGS_H +#ifndef VPSETTINGS_H +#define VPSETTINGS_H #include #include "vcommonsettings.h" -class VPuzzleSettings : public VCommonSettings +class VPSettings : public VCommonSettings { Q_OBJECT public: - VPuzzleSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), + VPSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), QObject *parent = nullptr); - VPuzzleSettings(const QString &fileName, Format format, QObject *parent = nullptr); + VPSettings(const QString &fileName, Format format, QObject *parent = nullptr); bool IsDockWidgetPropertiesActive() const; static bool GetDefDockWidgetPropertiesActive(); @@ -49,7 +49,7 @@ public: void SetDockWidgetPropertiesContentsActive(bool value); private: - Q_DISABLE_COPY(VPuzzleSettings) + Q_DISABLE_COPY(VPSettings) }; -#endif // VPUZZLESETTINGS_H +#endif // VPSETTINGS_H diff --git a/src/app/puzzle/vpsheet.cpp b/src/app/puzzle/vpsheet.cpp new file mode 100644 index 000000000..13b5a2a89 --- /dev/null +++ b/src/app/puzzle/vpsheet.cpp @@ -0,0 +1,204 @@ +/************************************************************************ + ** + ** @file vpsheet.cpp + ** @author Ronan Le Tiec + ** @date 23 5, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#include "vpsheet.h" + +#include "vppiecelist.h" +#include "vplayout.h" + +//--------------------------------------------------------------------------------------------------------------------- +VPSheet::VPSheet(VPLayout* layout) : + m_layout(layout) +{ + m_pieceList = new VPPieceList(layout, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPSheet::~VPSheet() +{ + delete m_pieceList; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPPieceList* VPSheet::GetPieceList() +{ + return m_pieceList; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VPSheet::GetName() const +{ + return m_name; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetName(const QString &name) +{ + m_name = name; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSize(qreal width, qreal height) +{ + m_size.setWidth(width); + m_size.setHeight(height); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSizeConverted(qreal width, qreal height) +{ + m_size.setWidth(UnitConvertor(width, m_layout->GetUnit(), Unit::Px)); + m_size.setHeight(UnitConvertor(height, m_layout->GetUnit(), Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSize(const QSizeF &size) +{ + m_size = size; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSizeConverted(const QSizeF &size) +{ + m_size = QSizeF( + UnitConvertor(size.width(), m_layout->GetUnit(), Unit::Px), + UnitConvertor(size.height(), m_layout->GetUnit(), Unit::Px) + ); +} + +//--------------------------------------------------------------------------------------------------------------------- +QSizeF VPSheet::GetSheetSize() const +{ + return m_size; +} + +//--------------------------------------------------------------------------------------------------------------------- +QSizeF VPSheet::GetSheetSizeConverted() const +{ + QSizeF convertedSize = QSizeF( + UnitConvertor(m_size.width(), Unit::Px, m_layout->GetUnit()), + UnitConvertor(m_size.height(), Unit::Px, m_layout->GetUnit()) + ); + + return convertedSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom) +{ + m_margins.setLeft(left); + m_margins.setTop(top); + m_margins.setRight(right); + m_margins.setBottom(bottom); +} +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMarginsConverted(qreal left, qreal top, qreal right, qreal bottom) +{ + m_margins.setLeft(UnitConvertor(left, m_layout->GetUnit(), Unit::Px)); + m_margins.setTop(UnitConvertor(top, m_layout->GetUnit(), Unit::Px)); + m_margins.setRight(UnitConvertor(right, m_layout->GetUnit(), Unit::Px)); + m_margins.setBottom(UnitConvertor(bottom, m_layout->GetUnit(), Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMargins(const QMarginsF &margins) +{ + m_margins = margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMarginsConverted(const QMarginsF &margins) +{ + m_margins = UnitConvertor(margins, m_layout->GetUnit(), Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VPSheet::GetSheetMargins() const +{ + return m_margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +QMarginsF VPSheet::GetSheetMarginsConverted() const +{ + return UnitConvertor(m_margins, Unit::Px, m_layout->GetUnit()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetFollowGrainline(FollowGrainline state) +{ + m_followGrainLine = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +FollowGrainline VPSheet::GetFollowGrainline() const +{ + return m_followGrainLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetPiecesGap(qreal value) +{ + m_piecesGap = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetPiecesGapConverted(qreal value) +{ + m_piecesGap = UnitConvertor(value, m_layout->GetUnit(), Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPSheet::GetPiecesGap() const +{ + return m_piecesGap; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPSheet::GetPiecesGapConverted() const +{ + return UnitConvertor(m_piecesGap, Unit::Px, m_layout->GetUnit()); +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetStickyEdges(bool state) +{ + m_stickyEdges = state; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPSheet::GetStickyEdges() const +{ + return m_stickyEdges; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::ClearSelection() +{ + m_pieceList->ClearSelection(); +} diff --git a/src/app/puzzle/vpsheet.h b/src/app/puzzle/vpsheet.h new file mode 100644 index 000000000..ea9fb58f4 --- /dev/null +++ b/src/app/puzzle/vpsheet.h @@ -0,0 +1,225 @@ +/************************************************************************ + ** + ** @file vpsheet.h + ** @author Ronan Le Tiec + ** @date 23 5, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#ifndef VPSHEET_H +#define VPSHEET_H + +#include +#include +#include +#include + +#include "def.h" + +// is this the right place for the definition? +enum class FollowGrainline : qint8 { No = 0, Follow90 = 1, Follow180 = 2}; + +class VPLayout; +class VPPieceList; + +class VPSheet : public QObject +{ + Q_OBJECT +public: + VPSheet(VPLayout* layout); + + ~VPSheet(); + + /** + * @brief GetPieceList returns the piece list of the sheet + * @return + */ + VPPieceList* GetPieceList(); + + /** + * @brief GetName Returns the name of the sheet + * @return the name + */ + QString GetName() const; + + /** + * @brief SetName Sets the name of the sheet to the given name + * @param name the new sheet's name + */ + void SetName(const QString &name); + + /** + * @brief SetSheetSize sets the size of the sheet, the values have to be in Unit::Px + * @param width sheet width + * @param height sheet height + */ + void SetSheetSize(qreal width, qreal height); + + /** + * @brief SetSheetSize sets the size of the sheet, the values have to be in the layout's unit + * @param width sheet width + * @param height sheet height + */ + void SetSheetSizeConverted(qreal width, qreal height); + + /** + * @brief SetSheetSize sets the size of the sheet, the values have to be in Unit::Px + * @param size sheet size + */ + void SetSheetSize(const QSizeF &size); + /** + * @brief SetSheetSizeConverted sets the size of the sheet, the values have to be in the layout's unit + * @param size sheet size + */ + void SetSheetSizeConverted(const QSizeF &size); + + /** + * @brief GetSheetSize Returns the size in Unit::Px + * @return sheet size in Unit::Px + */ + QSizeF GetSheetSize() const; + + /** + * @brief GetSheetSizeConverted Returns the size in the layout's unit + * @return the size in the layout's unit + */ + QSizeF GetSheetSizeConverted() const; + + /** + * @brief SetSheetMargins, set the margins of the sheet, the values have to be in Unit::Px + * @param left in Unit::Px + * @param top in Unit::Px + * @param right in Unit::Px + * @param bottom in Unit::Px + */ + void SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetSheetMargins, set the margins of the sheet, the values have to be in the unit of the layout + * @param left in Unit::Px + * @param top in Unit::Px + * @param right in Unit::Px + * @param bottom in Unit::Px + */ + void SetSheetMarginsConverted(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetSheetMargins set the margins of the sheet, the values have to be in Unit::Px + * @param margins sheet margins + */ + void SetSheetMargins(const QMarginsF &margins); + + /** + * @brief SetSheetMargins set the margins of the sheet, the values have to be in the unit of the layout + * @param margins sheet margins + */ + void SetSheetMarginsConverted(const QMarginsF &margins); + + /** + * @brief GetSheetMargins Returns the size in Unit::Px + * @return the size in Unit::Px + */ + QMarginsF GetSheetMargins() const; + + /** + * @brief GetSheetMarginsConverted Returns the margins in the layout's unit + * @return the margins in the sheet's unit + */ + QMarginsF GetSheetMarginsConverted() const; + + /** + * @brief SetFollowGrainline Sets the type of grainline for the pieces to follow + * @param state the type of grainline + */ + void SetFollowGrainline(FollowGrainline state); + + /** + * @brief GetFollowGrainline Returns if the sheet's pieces follow a grainline or not + * @return wether the pieces follow a grainline and if so, which grainline + */ + FollowGrainline GetFollowGrainline() const; + + /** + * @brief SetPiecesGap sets the pieces gap to the given value, the unit has to be in Unit::Px + * @param value pieces gap + */ + void SetPiecesGap(qreal value); + + /** + * @brief SetPiecesGapConverted sets the pieces gap to the given value, the unit has to be in the layout's unit + * @param value pieces gap + */ + void SetPiecesGapConverted(qreal value); + + /** + * @brief GetPiecesGap returns the pieces gap in Unit::Px + * @return the pieces gap in Unit::Px + */ + qreal GetPiecesGap() const; + + /** + * @brief GetPiecesGapConverted returns the pieces gap in the layout's unit + * @return the pieces gap in the layout's unit + */ + qreal GetPiecesGapConverted() const; + + /** + * @brief ClearSelection goes through the piece list and pieces and calls + * SetIsSelected(false) for the pieces that were selected. + */ + void ClearSelection(); + + void SetStickyEdges(bool state); + bool GetStickyEdges() const; + +private: + Q_DISABLE_COPY(VPSheet) + + VPLayout *m_layout; + + VPPieceList *m_pieceList {nullptr}; + + QString m_name{}; + + /** + * @brief m_size the Size in Unit::Px + */ + QSizeF m_size{}; + + // margins + /** + * @brief m_margins the margins in Unit::Px + */ + QMarginsF m_margins{}; + + // control + FollowGrainline m_followGrainLine{FollowGrainline::No}; + + /** + * @brief m_piecesGap the pieces gap in Unit::Px + */ + qreal m_piecesGap{0}; + + bool m_stickyEdges{false}; +}; + +#endif // VPSHEET_H diff --git a/src/app/puzzle/stable.cpp b/src/app/puzzle/vpstable.cpp similarity index 96% rename from src/app/puzzle/stable.cpp rename to src/app/puzzle/vpstable.cpp index 460b5cb9c..3db0e2a5d 100644 --- a/src/app/puzzle/stable.cpp +++ b/src/app/puzzle/vpstable.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file stable.cpp + ** @file vpstable.cpp ** @author Roman Telezhynskyi ** @date November 15, 2013 ** @@ -27,4 +27,4 @@ *************************************************************************/ // Build the precompiled headers. -#include "stable.h" +#include "vpstable.h" diff --git a/src/app/puzzle/stable.h b/src/app/puzzle/vpstable.h similarity index 96% rename from src/app/puzzle/stable.h rename to src/app/puzzle/vpstable.h index 22e9d4702..b986a6f7c 100644 --- a/src/app/puzzle/stable.h +++ b/src/app/puzzle/vpstable.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file stable.h + ** @file vpstable.h ** @author Roman Telezhynskyi ** @date November 15, 2013 ** @@ -26,8 +26,8 @@ ** *************************************************************************/ -#ifndef STABLE_H -#define STABLE_H +#ifndef VPSTABLE_H +#define VPSTABLE_H /* I like to include this pragma too, so the build log indicates if pre-compiled headers were in use. */ #pragma message("Compiling precompiled headers for puzzle utility.\n") @@ -69,4 +69,4 @@ #endif /*__cplusplus*/ -#endif // STABLE_H +#endif // VPSTABLE_H diff --git a/src/app/puzzle/vpuzzlelayout.cpp b/src/app/puzzle/vpuzzlelayout.cpp deleted file mode 100644 index 9020f3dac..000000000 --- a/src/app/puzzle/vpuzzlelayout.cpp +++ /dev/null @@ -1,318 +0,0 @@ -/************************************************************************ - ** - ** @file vpuzzlelayout.cpp - ** @author Ronan Le Tiec - ** @date 13 4, 2020 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2020 Valentina project - ** All Rights Reserved. - ** - ** Valentina 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 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ -#include "vpuzzlelayout.h" -#include "vpuzzlelayer.h" -#include "vpuzzlepiece.h" - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayout::VPuzzleLayout() : - m_unplacedPiecesLayer(new VPuzzleLayer(this)) -{ - m_unplacedPiecesLayer->SetName(QObject::tr("Unplaced pieces")); - - // create a standard default layer: - VPuzzleLayer *layer = new VPuzzleLayer(this); - layer->SetName(QObject::tr("Layout")); - AddLayer(layer); - - // sets the default active layer - SetFocusedLayer(); -} - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayout::~VPuzzleLayout() -{ - qDeleteAll(m_layers); - delete m_unplacedPiecesLayer; -} - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayer* VPuzzleLayout::GetUnplacedPiecesLayer() -{ - return m_unplacedPiecesLayer; -} - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayer* VPuzzleLayout::AddLayer() -{ - VPuzzleLayer *newLayer = new VPuzzleLayer(this); - m_layers.append(newLayer); - return newLayer; -} - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayer* VPuzzleLayout::AddLayer(VPuzzleLayer *layer) -{ - m_layers.append(layer); - return layer; -} - -//--------------------------------------------------------------------------------------------------------------------- -QList VPuzzleLayout::GetLayers() -{ - return m_layers; -} - -//--------------------------------------------------------------------------------------------------------------------- -QList VPuzzleLayout::GetSelectedPieces() -{ - QList result = QList(); - - QList layers = m_layers; - layers.prepend(m_unplacedPiecesLayer); - - for (auto layer : layers) - { - for (auto piece : layer->GetPieces()) - { - if(piece->GetIsSelected()) - { - result.append(piece); - } - } - } - - return result; -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetUnit(Unit unit) -{ - m_unit = unit; -} - -//--------------------------------------------------------------------------------------------------------------------- -Unit VPuzzleLayout::GetUnit() const -{ - return m_unit; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetLayoutSize(qreal width, qreal height) -{ - m_size.setWidth(width); - m_size.setHeight(height); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetLayoutSizeConverted(qreal width, qreal height) -{ - m_size.setWidth(UnitConvertor(width, m_unit, Unit::Px)); - m_size.setHeight(UnitConvertor(height, m_unit, Unit::Px)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetLayoutSize(const QSizeF &size) -{ - m_size = size; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetLayoutSizeConverted(const QSizeF &size) -{ - m_size = QSizeF( - UnitConvertor(size.width(), m_unit, Unit::Px), - UnitConvertor(size.height(), m_unit, Unit::Px) - ); -} - -//--------------------------------------------------------------------------------------------------------------------- -QSizeF VPuzzleLayout::GetLayoutSize() const -{ - return m_size; -} - -//--------------------------------------------------------------------------------------------------------------------- -QSizeF VPuzzleLayout::GetLayoutSizeConverted() const -{ - QSizeF convertedSize = QSizeF( - UnitConvertor(m_size.width(), Unit::Px, m_unit), - UnitConvertor(m_size.height(), Unit::Px, m_unit) - ); - - return convertedSize; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom) -{ - m_margins.setLeft(left); - m_margins.setTop(top); - m_margins.setRight(right); - m_margins.setBottom(bottom); -} -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetLayoutMarginsConverted(qreal left, qreal top, qreal right, qreal bottom) -{ - m_margins.setLeft(UnitConvertor(left, m_unit, Unit::Px)); - m_margins.setTop(UnitConvertor(top, m_unit, Unit::Px)); - m_margins.setRight(UnitConvertor(right, m_unit, Unit::Px)); - m_margins.setBottom(UnitConvertor(bottom, m_unit, Unit::Px)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetLayoutMargins(const QMarginsF &margins) -{ - m_margins = margins; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetLayoutMarginsConverted(const QMarginsF &margins) -{ - m_margins = UnitConvertor(margins, m_unit, Unit::Px); -} - -//--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPuzzleLayout::GetLayoutMargins() const -{ - return m_margins; -} - -//--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPuzzleLayout::GetLayoutMarginsConverted() const -{ - return UnitConvertor(m_margins, Unit::Px, m_unit); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetFollowGrainline(FollowGrainline state) -{ - m_followGrainLine = state; -} - -//--------------------------------------------------------------------------------------------------------------------- -FollowGrainline VPuzzleLayout::GetFollowGrainline() const -{ - return m_followGrainLine; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetPiecesGap(qreal value) -{ - m_piecesGap = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetPiecesGapConverted(qreal value) -{ - m_piecesGap = UnitConvertor(value, m_unit, Unit::Px); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPuzzleLayout::GetPiecesGap() const -{ - return m_piecesGap; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPuzzleLayout::GetPiecesGapConverted() const -{ - return UnitConvertor(m_piecesGap, Unit::Px, m_unit); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetWarningSuperpositionOfPieces(bool state) -{ - m_warningSuperpositionOfPieces = state; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleLayout::GetWarningSuperpositionOfPieces() const -{ - return m_warningSuperpositionOfPieces; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetWarningPiecesOutOfBound(bool state) -{ - m_warningPiecesOutOfBound = state; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleLayout::GetWarningPiecesOutOfBound() const -{ - return m_warningPiecesOutOfBound; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetStickyEdges(bool state) -{ - m_stickyEdges = state; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleLayout::GetStickyEdges() const -{ - return m_stickyEdges; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::ClearSelection() -{ - m_unplacedPiecesLayer->ClearSelection(); - - for (auto layer : m_layers) - { - layer->ClearSelection(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::SetFocusedLayer(VPuzzleLayer* focusedLayer) -{ - if(focusedLayer == nullptr) - { - m_focusedLayer = m_layers.first(); - } - else - { - m_focusedLayer = focusedLayer; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayer* VPuzzleLayout::GetFocusedLayer() -{ - return m_focusedLayer; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayout::MovePieceToLayer(VPuzzlePiece* piece, VPuzzleLayer* layer) -{ - VPuzzleLayer* layerBefore = piece->GetLayer(); - - if(layerBefore != nullptr) - { - piece->GetLayer()->RemovePiece(piece); - } - layer->AddPiece(piece); - - // signal, that a piece was moved - emit PieceMovedToLayer(piece, layerBefore,layer); -} diff --git a/src/app/puzzle/vpuzzlelayout.h b/src/app/puzzle/vpuzzlelayout.h deleted file mode 100644 index 26ab1da3f..000000000 --- a/src/app/puzzle/vpuzzlelayout.h +++ /dev/null @@ -1,267 +0,0 @@ -/************************************************************************ - ** - ** @file vpuzzlelayout.h - ** @author Ronan Le Tiec - ** @date 13 4, 2020 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2020 Valentina project - ** All Rights Reserved. - ** - ** Valentina 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 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ -#ifndef VPUZZLELAYOUT_H -#define VPUZZLELAYOUT_H - -#include -#include -#include - -#include "def.h" - -class VPuzzleLayer; -class VPuzzlePiece; - -// is this the right place for the definition? -enum class FollowGrainline : qint8 { No = 0, Follow90 = 1, Follow180 = 2}; - -class VPuzzleLayout : public QObject -{ - Q_OBJECT -public: - VPuzzleLayout(); - virtual ~VPuzzleLayout(); - - VPuzzleLayer* GetUnplacedPiecesLayer(); - - VPuzzleLayer* AddLayer(); - VPuzzleLayer* AddLayer(VPuzzleLayer *layer); - QList GetLayers(); - - /** - * @brief GetSelectedPieces Returns the list of the selected pieces - * @return the selected pieces - */ - QList GetSelectedPieces(); - - /** - * @brief SetUnit Sets the unit of the layout to the given unit - * @param unit the new unit - */ - void SetUnit(Unit unit); - - /** - * @brief GetUnit Returns the current unit of the layout - * @return the unit - */ - Unit GetUnit() const; - - /** - * @brief SetLayoutSize sets the size of the layout, the values have to be in Unit::Px - * @param width layout width - * @param height layout height - */ - void SetLayoutSize(qreal width, qreal height); - - /** - * @brief SetLayoutSize sets the size of the layout, the values have to be in the layout's unit - * @param width layout width - * @param height layout height - */ - void SetLayoutSizeConverted(qreal width, qreal height); - - /** - * @brief SetLayoutSize sets the size of the layout, the values have to be in Unit::Px - * @param size layout size - */ - void SetLayoutSize(const QSizeF &size); - /** - * @brief SetLayoutSizeConverted sets the size of the layout, the values have to be in the layout's unit - * @param size layout size - */ - void SetLayoutSizeConverted(const QSizeF &size); - - /** - * @brief GetLayoutSize Returns the size in Unit::Px - * @return layout size in Unit::Px - */ - QSizeF GetLayoutSize() const; - - /** - * @brief GetLayoutSizeConverted Returns the size in the layout's unit - * @return the size in the layout's unit - */ - QSizeF GetLayoutSizeConverted() const; - - /** - * @brief SetLayoutMargins, set the margins of the layout, the values have to be in Unit::Px - * @param left in Unit::Px - * @param top in Unit::Px - * @param right in Unit::Px - * @param bottom in Unit::Px - */ - void SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom); - - /** - * @brief SetLayoutMargins, set the margins of the layout, the values have to be in the unit of the layout - * @param left in Unit::Px - * @param top in Unit::Px - * @param right in Unit::Px - * @param bottom in Unit::Px - */ - void SetLayoutMarginsConverted(qreal left, qreal top, qreal right, qreal bottom); - - /** - * @brief SetLayoutMargins set the margins of the layout, the values have to be in Unit::Px - * @param margins layout margins - */ - void SetLayoutMargins(const QMarginsF &margins); - - /** - * @brief SetLayoutMargins set the margins of the layout, the values have to be in the unit of the layout - * @param margins layout margins - */ - void SetLayoutMarginsConverted(const QMarginsF &margins); - - /** - * @brief GetLayoutMargins Returns the size in Unit::Px - * @return the size in Unit::Px - */ - QMarginsF GetLayoutMargins() const; - - /** - * @brief GetLayoutMarginsConverted Returns the margins in the layout's unit - * @return the margins in the layout's unit - */ - QMarginsF GetLayoutMarginsConverted() const; - - /** - * @brief SetFollowGrainline Sets the type of grainline for the pieces to follow - * @param state the type of grainline - */ - void SetFollowGrainline(FollowGrainline state); - - /** - * @brief GetFollowGrainline Returns if the layout's pieces follow a grainline or not - * @return wether the pieces follow a grainline and if so, which grainline - */ - FollowGrainline GetFollowGrainline() const; - - /** - * @brief SetPiecesGap sets the pieces gap to the given value, the unit has to be in Unit::Px - * @param value pieces gap - */ - void SetPiecesGap(qreal value); - - /** - * @brief SetPiecesGapConverted sets the pieces gap to the given value, the unit has to be in the layout's unit - * @param value pieces gap - */ - void SetPiecesGapConverted(qreal value); - - /** - * @brief GetPiecesGap returns the pieces gap in Unit::Px - * @return the pieces gap in Unit::Px - */ - qreal GetPiecesGap() const; - - /** - * @brief GetPiecesGapConverted returns the pieces gap in the layout's unit - * @return the pieces gap in the layout's unit - */ - qreal GetPiecesGapConverted() const; - - void SetWarningSuperpositionOfPieces(bool state); - bool GetWarningSuperpositionOfPieces() const; - - void SetWarningPiecesOutOfBound(bool state); - bool GetWarningPiecesOutOfBound() const; - - void SetStickyEdges(bool state); - bool GetStickyEdges() const; - - /** - * @brief ClearSelection goes through the layers & pieces and calls - * SetIsSelected(false) for the pieces that were selected. - */ - void ClearSelection(); - - /** - * @brief SetFocusedLayer Sets the focused layer, to which pieces are added from the carrousel via drag - * and drop - * @param focusedLayer the new active layer. If nullptr, then it sets automaticaly the first layer from m_layers - */ - void SetFocusedLayer(VPuzzleLayer* focusedLayer = nullptr); - - /** - * @brief GetFocusedLayer Returns the focused layer, to which pieces are added from the carrousel via drag - * and drop - * @return the focused layer - */ - VPuzzleLayer* GetFocusedLayer(); - - /** - * @brief MovePieceToLayer Moves the given piece to the given layer - * @param piece the piece to move - * @param layer the layer to move the piece to - */ - void MovePieceToLayer(VPuzzlePiece* piece, VPuzzleLayer* layer); - -signals: - - void PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleLayer *layerBefore, VPuzzleLayer *layerAfter); - -private: - Q_DISABLE_COPY(VPuzzleLayout) - - VPuzzleLayer *m_unplacedPiecesLayer; - QList m_layers{}; - - /** - * @brief m_focusedLayer pointer the the focused layer, to which pieces will be - * added via drag and drop, or if no layer is defined. - */ - VPuzzleLayer *m_focusedLayer{nullptr}; - - // format - Unit m_unit{Unit::Cm}; - /** - * @brief m_size the Size in Unit::Px - */ - QSizeF m_size{}; - - // margins - /** - * @brief m_margins the margins in Unit::Px - */ - QMarginsF m_margins{}; - - // control - FollowGrainline m_followGrainLine{FollowGrainline::No}; - - /** - * @brief m_piecesGap the pieces gap in Unit::Px - */ - qreal m_piecesGap{0}; - bool m_warningSuperpositionOfPieces{false}; - bool m_warningPiecesOutOfBound{false}; - bool m_stickyEdges{false}; - -}; - -#endif // VPUZZLELAYOUT_H diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp similarity index 79% rename from src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp rename to src/app/puzzle/xml/vplayoutfilereader.cpp index 31ab72691..233bf6c65 100644 --- a/src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlelayoutfilereader.cpp + ** @file vplayoutfilereader.cpp ** @author Ronan Le Tiec ** @date 18 4, 2020 ** @@ -27,27 +27,27 @@ ** *************************************************************************/ #include -#include "vpuzzlelayoutfilereader.h" -#include "vpuzzlelayoutfilewriter.h" -#include "layoutliterals.h" +#include "vplayoutfilereader.h" +#include "vplayoutfilewriter.h" +#include "vplayoutliterals.h" #include "../ifc/exception/vexception.h" #include "../ifc/exception/vexceptionconversionerror.h" //--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayoutFileReader::VPuzzleLayoutFileReader() +VPLayoutFileReader::VPLayoutFileReader() { } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayoutFileReader::~VPuzzleLayoutFileReader() +VPLayoutFileReader::~VPLayoutFileReader() { // TODO } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleLayoutFileReader::ReadFile(VPuzzleLayout *layout, QFile *file) +bool VPLayoutFileReader::ReadFile(VPLayout *layout, QFile *file) { setDevice(file); @@ -60,7 +60,7 @@ bool VPuzzleLayoutFileReader::ReadFile(VPuzzleLayout *layout, QFile *file) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout) +void VPLayoutFileReader::ReadLayout(VPLayout *layout) { SCASSERT(isStartElement() && name() == ML::TagLayout); @@ -70,9 +70,13 @@ void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout) { ReadProperties(layout); } - else if (name() == ML::TagLayers) + else if (name() == ML::TagPieceLists) { - ReadLayers(layout); + ReadSheets(layout); + } + else if (name() == ML::TagUnplacedPieceList) + { + ReadUnplacedPieces(layout); } else { @@ -82,7 +86,7 @@ void VPuzzleLayoutFileReader::ReadLayout(VPuzzleLayout *layout) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileReader::ReadProperties(VPuzzleLayout *layout) +void VPLayoutFileReader::ReadProperties(VPLayout *layout) { SCASSERT(isStartElement() && name() == ML::TagProperties); @@ -94,8 +98,6 @@ void VPuzzleLayoutFileReader::ReadProperties(VPuzzleLayout *layout) { ML::TagUnit, ML::TagDescription, - ML::TagSize, - ML::TagMargin, ML::TagControl, ML::TagTiles }); @@ -113,38 +115,17 @@ void VPuzzleLayoutFileReader::ReadProperties(VPuzzleLayout *layout) // TODO read the description info break; } - case 2:// size - { - qDebug("read size"); - QSizeF size = ReadSize(); - layout->SetLayoutSize(size); - readElementText(); - break; - } - case 3:// margin - { - qDebug("read margin"); - QMarginsF margins = ReadMargins(); - layout->SetLayoutMargins(margins); - readElementText(); - break; - } - case 4:// control + case 2:// control { qDebug("read control"); QXmlStreamAttributes attribs = attributes(); - - // attribs.value("followGrainLine"); // TODO - layout->SetWarningSuperpositionOfPieces(ReadAttributeBool(attribs, ML::AttrWarningSuperposition, trueStr)); layout->SetWarningPiecesOutOfBound(ReadAttributeBool(attribs, ML::AttrWarningOutOfBound, trueStr)); - layout->SetStickyEdges(ReadAttributeBool(attribs, ML::AttrStickyEdges, trueStr)); - layout->SetPiecesGap(ReadAttributeDouble(attribs, ML::AttrPiecesGap, QChar('0'))); readElementText(); break; } - case 5:// tiles + case 3:// tiles qDebug("read tiles"); ReadTiles(layout); readElementText(); @@ -158,7 +139,13 @@ void VPuzzleLayoutFileReader::ReadProperties(VPuzzleLayout *layout) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileReader::ReadTiles(VPuzzleLayout *layout) +void VPLayoutFileReader::ReadUnplacedPieces(VPLayout *layout) +{ + ReadPieceList(layout->GetUnplacedPieceList()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadTiles(VPLayout *layout) { Q_UNUSED(layout); // to be removed when used @@ -193,20 +180,15 @@ void VPuzzleLayoutFileReader::ReadTiles(VPuzzleLayout *layout) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout) +void VPLayoutFileReader::ReadSheets(VPLayout *layout) { - SCASSERT(isStartElement() && name() == ML::TagLayers); + SCASSERT(isStartElement() && name() == ML::TagSheets); while (readNextStartElement()) { - if (name() == ML::TagUnplacedPiecesLayer) + if (name() == ML::TagSheet) { - ReadLayer(layout->GetUnplacedPiecesLayer()); - } - else if (name() == ML::TagLayer) - { - VPuzzleLayer *layer = layout->AddLayer(); - ReadLayer(layer); + ReadSheet(layout); } else { @@ -217,21 +199,29 @@ void VPuzzleLayoutFileReader::ReadLayers(VPuzzleLayout *layout) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer) +void VPLayoutFileReader::ReadSheet(VPLayout *layout) { - SCASSERT(isStartElement() && (name() == ML::TagLayer || name() == ML::TagUnplacedPiecesLayer)); + Q_UNUSED(layout); + // TODO +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadPieceList(VPPieceList *pieceList) +{ + SCASSERT(isStartElement() && (name() == ML::TagPieceList || name() == ML::TagUnplacedPieceList)); QXmlStreamAttributes attribs = attributes(); - layer->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Layer"))); - layer->SetIsVisible(ReadAttributeBool(attribs, ML::AttrVisible, trueStr)); + pieceList->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece List"))); + pieceList->SetIsVisible(ReadAttributeBool(attribs, ML::AttrVisible, trueStr)); while (readNextStartElement()) { if (name() == ML::TagPiece) { - VPuzzlePiece *piece = new VPuzzlePiece(); + VPPiece *piece = new VPPiece(); ReadPiece(piece); - layer->AddPiece(piece); + pieceList->AddPiece(piece); } else { @@ -242,7 +232,7 @@ void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileReader::ReadPiece(VPuzzlePiece *piece) +void VPLayoutFileReader::ReadPiece(VPPiece *piece) { Q_UNUSED(piece); SCASSERT(isStartElement() && name() == ML::TagPiece); @@ -278,7 +268,7 @@ void VPuzzleLayoutFileReader::ReadPiece(VPuzzlePiece *piece) } //--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPuzzleLayoutFileReader::ReadMargins() +QMarginsF VPLayoutFileReader::ReadMargins() { QMarginsF margins = QMarginsF(); @@ -292,7 +282,7 @@ QMarginsF VPuzzleLayoutFileReader::ReadMargins() } //--------------------------------------------------------------------------------------------------------------------- -QSizeF VPuzzleLayoutFileReader::ReadSize() +QSizeF VPLayoutFileReader::ReadSize() { QSizeF size = QSize(); @@ -304,7 +294,7 @@ QSizeF VPuzzleLayoutFileReader::ReadSize() } //--------------------------------------------------------------------------------------------------------------------- -QString VPuzzleLayoutFileReader::ReadAttributeString(const QXmlStreamAttributes &attribs, const QString &name, +QString VPLayoutFileReader::ReadAttributeString(const QXmlStreamAttributes &attribs, const QString &name, const QString &defValue) { const QString parameter = attribs.value(name).toString(); @@ -323,13 +313,13 @@ QString VPuzzleLayoutFileReader::ReadAttributeString(const QXmlStreamAttributes } //--------------------------------------------------------------------------------------------------------------------- -QString VPuzzleLayoutFileReader::ReadAttributeEmptyString(const QXmlStreamAttributes &attribs, const QString &name) +QString VPLayoutFileReader::ReadAttributeEmptyString(const QXmlStreamAttributes &attribs, const QString &name) { return attribs.value(name).toString(); } //--------------------------------------------------------------------------------------------------------------------- -bool VPuzzleLayoutFileReader::ReadAttributeBool(const QXmlStreamAttributes &attribs, const QString &name, +bool VPLayoutFileReader::ReadAttributeBool(const QXmlStreamAttributes &attribs, const QString &name, const QString &defValue) { QString parametr; @@ -366,7 +356,7 @@ bool VPuzzleLayoutFileReader::ReadAttributeBool(const QXmlStreamAttributes &attr } //--------------------------------------------------------------------------------------------------------------------- -qreal VPuzzleLayoutFileReader::ReadAttributeDouble(const QXmlStreamAttributes &attribs, const QString &name, +qreal VPLayoutFileReader::ReadAttributeDouble(const QXmlStreamAttributes &attribs, const QString &name, const QString &defValue) { bool ok = false; diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilereader.h b/src/app/puzzle/xml/vplayoutfilereader.h similarity index 71% rename from src/app/puzzle/xml/vpuzzlelayoutfilereader.h rename to src/app/puzzle/xml/vplayoutfilereader.h index 7f4c00e1a..7ed40f1a8 100644 --- a/src/app/puzzle/xml/vpuzzlelayoutfilereader.h +++ b/src/app/puzzle/xml/vplayoutfilereader.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlelayoutfilereader.h + ** @file vplayoutfilereader.h ** @author Ronan Le Tiec ** @date 18 4, 2020 ** @@ -26,33 +26,35 @@ ** ** *************************************************************************/ -#ifndef VPUZZLELAYOUTFILEREADER_H -#define VPUZZLELAYOUTFILEREADER_H +#ifndef VPLAYOUTFILEREADER_H +#define VPLAYOUTFILEREADER_H #include #include "../ifc/xml/vabstractconverter.h" -#include "vpuzzlelayout.h" -#include "vpuzzlelayer.h" -#include "vpuzzlepiece.h" +#include "vplayout.h" +#include "vppiecelist.h" +#include "vppiece.h" -class VPuzzleLayoutFileReader : public QXmlStreamReader +class VPLayoutFileReader : public QXmlStreamReader { - Q_DECLARE_TR_FUNCTIONS(VPuzzleLayoutFileReader) + Q_DECLARE_TR_FUNCTIONS(VPLayoutFileReader) public: - VPuzzleLayoutFileReader(); - ~VPuzzleLayoutFileReader(); + VPLayoutFileReader(); + ~VPLayoutFileReader(); - bool ReadFile(VPuzzleLayout *layout, QFile *file); + bool ReadFile(VPLayout *layout, QFile *file); private: - Q_DISABLE_COPY(VPuzzleLayoutFileReader) + Q_DISABLE_COPY(VPLayoutFileReader) - void ReadLayout(VPuzzleLayout *layout); - void ReadProperties(VPuzzleLayout *layout); - void ReadTiles(VPuzzleLayout *layout); - void ReadLayers(VPuzzleLayout *layout); - void ReadLayer(VPuzzleLayer *layer); - void ReadPiece(VPuzzlePiece *piece); + void ReadLayout(VPLayout *layout); + void ReadProperties(VPLayout *layout); + void ReadTiles(VPLayout *layout); + void ReadUnplacedPieces(VPLayout *layout); + void ReadSheets(VPLayout *layout); + void ReadSheet(VPLayout *layout); + void ReadPieceList(VPPieceList *pieceList); + void ReadPiece(VPPiece *piece); QMarginsF ReadMargins(); QSizeF ReadSize(); @@ -65,4 +67,4 @@ private: const QString &defValue); }; -#endif // VPUZZLELAYOUTFILEREADER_H +#endif // VPLAYOUTFILEREADER_H diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp similarity index 74% rename from src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp rename to src/app/puzzle/xml/vplayoutfilewriter.cpp index 6b8dced26..327e01aaf 100644 --- a/src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlelayoutfilewriter.cpp + ** @file vplayoutfilewriter.cpp ** @author Ronan Le Tiec ** @date 18 4, 2020 ** @@ -26,27 +26,28 @@ ** *************************************************************************/ -#include "vpuzzlelayoutfilewriter.h" -#include "vpuzzlelayout.h" -#include "vpuzzlelayer.h" -#include "vpuzzlepiece.h" -#include "layoutliterals.h" +#include "vplayoutfilewriter.h" +#include "vplayout.h" +#include "vpsheet.h" +#include "vppiecelist.h" +#include "vppiece.h" +#include "vplayoutliterals.h" #include "../ifc/xml/vlayoutconverter.h" //--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayoutFileWriter::VPuzzleLayoutFileWriter() +VPLayoutFileWriter::VPLayoutFileWriter() { } //--------------------------------------------------------------------------------------------------------------------- -VPuzzleLayoutFileWriter::~VPuzzleLayoutFileWriter() +VPLayoutFileWriter::~VPLayoutFileWriter() { } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WriteFile(VPuzzleLayout *layout, QFile *file) +void VPLayoutFileWriter::WriteFile(VPLayout *layout, QFile *file) { setDevice(file); setAutoFormatting(true); @@ -59,19 +60,19 @@ void VPuzzleLayoutFileWriter::WriteFile(VPuzzleLayout *layout, QFile *file) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WriteLayout(VPuzzleLayout *layout) +void VPLayoutFileWriter::WriteLayout(VPLayout *layout) { writeStartElement(ML::TagLayout); SetAttribute(ML::AttrVersion, VLayoutConverter::LayoutMaxVerStr); WriteProperties(layout); - WriteLayers(layout); + WriteUnplacePiecesList(layout); writeEndElement(); //layout } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WriteProperties(VPuzzleLayout *layout) +void VPLayoutFileWriter::WriteProperties(VPLayout *layout) { writeStartElement(ML::TagProperties); @@ -79,16 +80,10 @@ void VPuzzleLayoutFileWriter::WriteProperties(VPuzzleLayout *layout) writeTextElement(ML::TagDescription, QString()); // TODO : define the value in layout - WriteSize(layout->GetLayoutSize()); - - WriteMargins(layout->GetLayoutMargins()); - writeStartElement(ML::TagControl); - SetAttribute(ML::AttrFollowGrainLine, "no"); // TODO / Fixme get the right value + SetAttribute(ML::AttrWarningSuperposition, layout->GetWarningSuperpositionOfPieces()); SetAttribute(ML::AttrWarningOutOfBound, layout->GetWarningPiecesOutOfBound()); - SetAttribute(ML::AttrStickyEdges, layout->GetStickyEdges()); - SetAttribute(ML::AttrPiecesGap, layout->GetPiecesGap()); writeEndElement(); // control // WriteTiles(layout); TODO: when tile functionality implemented, then uncomment this line @@ -97,7 +92,33 @@ void VPuzzleLayoutFileWriter::WriteProperties(VPuzzleLayout *layout) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WriteTiles(VPuzzleLayout *layout) +void VPLayoutFileWriter::WriteUnplacePiecesList(VPLayout *layout) +{ + Q_UNUSED(layout); + // TODO +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileWriter::WriteSheets(VPLayout *layout) +{ + Q_UNUSED(layout); + // TODO +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileWriter::WriteSheet(VPSheet* sheet) +{ + Q_UNUSED(sheet); + // TODO + + // WritePieceList(pieceList); + +} + + + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileWriter::WriteTiles(VPLayout *layout) { Q_UNUSED(layout); // to be removed @@ -116,49 +137,32 @@ void VPuzzleLayoutFileWriter::WriteTiles(VPuzzleLayout *layout) //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WriteLayers(VPuzzleLayout *layout) +void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList) { - writeStartElement(ML::TagLayers); - - WriteLayer(layout->GetUnplacedPiecesLayer(), ML::TagUnplacedPiecesLayer); - - QList layers = layout->GetLayers(); - for (auto layer : layers) - { - WriteLayer(layer); - } - - writeEndElement(); // layers -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WriteLayer(VPuzzleLayer *layer) -{ - WriteLayer(layer, ML::TagLayer); + WritePieceList(pieceList, ML::TagPieceList); } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WriteLayer(VPuzzleLayer *layer, const QString &tagName) +void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList, const QString &tagName) { - writeStartElement(tagName); // layer - SetAttribute(ML::AttrName, layer->GetName()); - SetAttribute(ML::AttrVisible, layer->GetIsVisible()); + writeStartElement(tagName); // piece list + SetAttribute(ML::AttrName, pieceList->GetName()); + SetAttribute(ML::AttrVisible, pieceList->GetIsVisible()); // TODO selected info. Not sure how it's saved yet - //SetAttribute("selected", layer->GetIsSelected()); + //SetAttribute("selected", pieceList->GetIsSelected()); - QList pieces = layer->GetPieces(); + QList pieces = pieceList->GetPieces(); for (auto piece : pieces) { WritePiece(piece); } - writeEndElement(); // layer + writeEndElement(); // piece list } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WritePiece(VPuzzlePiece *piece) +void VPLayoutFileWriter::WritePiece(VPPiece *piece) { Q_UNUSED(piece); @@ -182,7 +186,7 @@ void VPuzzleLayoutFileWriter::WritePiece(VPuzzlePiece *piece) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WriteMargins(const QMarginsF &margins) +void VPLayoutFileWriter::WriteMargins(const QMarginsF &margins) { writeStartElement(ML::TagMargin); SetAttribute(ML::AttrLeft, margins.left()); @@ -193,7 +197,7 @@ void VPuzzleLayoutFileWriter::WriteMargins(const QMarginsF &margins) } //--------------------------------------------------------------------------------------------------------------------- -void VPuzzleLayoutFileWriter::WriteSize(QSizeF size) +void VPLayoutFileWriter::WriteSize(QSizeF size) { // maybe not necessary to test this, the writer should "stupidly write", the application should take care of these tests qreal width = size.width(); diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilewriter.h b/src/app/puzzle/xml/vplayoutfilewriter.h similarity index 68% rename from src/app/puzzle/xml/vpuzzlelayoutfilewriter.h rename to src/app/puzzle/xml/vplayoutfilewriter.h index abbc7377f..4498277c4 100644 --- a/src/app/puzzle/xml/vpuzzlelayoutfilewriter.h +++ b/src/app/puzzle/xml/vplayoutfilewriter.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpuzzlelayoutfilewriter.h + ** @file vplayoutfilewriter.h ** @author Ronan Le Tiec ** @date 18 4, 2020 ** @@ -26,37 +26,40 @@ ** ** *************************************************************************/ -#ifndef VPUZZLELAYOUTFILEWRITER_H -#define VPUZZLELAYOUTFILEWRITER_H +#ifndef VPLAYOUTFILEWRITER_H +#define VPLAYOUTFILEWRITER_H #include #include #include "../vmisc/literals.h" -class VPuzzleLayout; -class VPuzzleLayer; -class VPuzzlePiece; +class VPLayout; +class VPSheet; +class VPPieceList; +class VPPiece; class QFile; class QMarginsF; -class VPuzzleLayoutFileWriter : public QXmlStreamWriter +class VPLayoutFileWriter : public QXmlStreamWriter { public: - VPuzzleLayoutFileWriter(); - ~VPuzzleLayoutFileWriter(); + VPLayoutFileWriter(); + ~VPLayoutFileWriter(); - void WriteFile(VPuzzleLayout *layout, QFile *file); + void WriteFile(VPLayout *layout, QFile *file); private: - void WriteLayout(VPuzzleLayout *layout); - void WriteProperties(VPuzzleLayout *layout); - void WriteTiles(VPuzzleLayout *layout); - void WriteLayers(VPuzzleLayout *layout); - void WriteLayer(VPuzzleLayer *layer); - void WriteLayer(VPuzzleLayer *layer, const QString &tagName); - void WritePiece(VPuzzlePiece *piece); + void WriteLayout(VPLayout *layout); + void WriteProperties(VPLayout *layout); + void WriteUnplacePiecesList(VPLayout *layout); + void WriteSheets(VPLayout *layout); + void WriteSheet(VPSheet* sheet); + void WriteTiles(VPLayout *layout); + void WritePieceList(VPPieceList *pieceList); + void WritePieceList(VPPieceList *pieceList, const QString &tagName); + void WritePiece(VPPiece *piece); void WriteMargins(const QMarginsF &margins); void WriteSize(QSizeF size); @@ -71,7 +74,7 @@ private: //--------------------------------------------------------------------------------------------------------------------- template -void VPuzzleLayoutFileWriter::SetAttribute(const QString &name, const T &value) +void VPLayoutFileWriter::SetAttribute(const QString &name, const T &value) { // See specification for xs:decimal const QLocale locale = QLocale::c(); @@ -80,30 +83,30 @@ void VPuzzleLayoutFileWriter::SetAttribute(const QString &name, const T &value) //--------------------------------------------------------------------------------------------------------------------- template <> -inline void VPuzzleLayoutFileWriter::SetAttribute(const QString &name, const QString &value) +inline void VPLayoutFileWriter::SetAttribute(const QString &name, const QString &value) { writeAttribute(name, value); } //--------------------------------------------------------------------------------------------------------------------- template <> -inline void VPuzzleLayoutFileWriter::SetAttribute(const QString &name, const QChar &value) +inline void VPLayoutFileWriter::SetAttribute(const QString &name, const QChar &value) { writeAttribute(name, value); } //--------------------------------------------------------------------------------------------------------------------- template <> -inline void VPuzzleLayoutFileWriter::SetAttribute(const QString &name, const bool &value) +inline void VPLayoutFileWriter::SetAttribute(const QString &name, const bool &value) { writeAttribute(name, value ? trueStr : falseStr); } //--------------------------------------------------------------------------------------------------------------------- template -inline void VPuzzleLayoutFileWriter::SetAttribute(const QString &name, const char (&value)[N]) +inline void VPLayoutFileWriter::SetAttribute(const QString &name, const char (&value)[N]) { writeAttribute(name, QString(value)); } -#endif // VPUZZLELAYOUTFILEWRITER_H +#endif // VPLAYOUTFILEWRITER_H diff --git a/src/app/puzzle/xml/layoutliterals.cpp b/src/app/puzzle/xml/vplayoutliterals.cpp similarity index 88% rename from src/app/puzzle/xml/layoutliterals.cpp rename to src/app/puzzle/xml/vplayoutliterals.cpp index d73088fc8..ada2d2f37 100644 --- a/src/app/puzzle/xml/layoutliterals.cpp +++ b/src/app/puzzle/xml/vplayoutliterals.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file literals.cpp + ** @file vplayoutliterals.cpp ** @author Roman Telezhynskyi ** @date 23 4, 2020 ** @@ -25,22 +25,24 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#include "layoutliterals.h" +#include "vplayoutliterals.h" namespace ML { const QString TagLayout = QStringLiteral("layout"); const QString TagProperties = QStringLiteral("properties"); -const QString TagLayers = QStringLiteral("layers"); +const QString TagPieceLists = QStringLiteral("pieceLists"); const QString TagUnit = QStringLiteral("unit"); const QString TagDescription = QStringLiteral("description"); const QString TagSize = QStringLiteral("size"); const QString TagMargin = QStringLiteral("margin"); const QString TagControl = QStringLiteral("control"); const QString TagTiles = QStringLiteral("tiles"); -const QString TagUnplacedPiecesLayer = QStringLiteral("unplacedPiecesLayer"); -const QString TagLayer = QStringLiteral("layer"); +const QString TagUnplacedPieceList = QStringLiteral("unplacedPieceList"); +const QString TagPieceList = QStringLiteral("pieceList"); const QString TagPiece = QStringLiteral("piece"); +const QString TagSheets = QStringLiteral("sheets"); +const QString TagSheet = QStringLiteral("sheet"); const QString AttrVersion = QStringLiteral("version"); const QString AttrWarningSuperposition = QStringLiteral("warningSuperposition"); diff --git a/src/app/puzzle/xml/layoutliterals.h b/src/app/puzzle/xml/vplayoutliterals.h similarity index 88% rename from src/app/puzzle/xml/layoutliterals.h rename to src/app/puzzle/xml/vplayoutliterals.h index 82157f9bf..0f1278b7d 100644 --- a/src/app/puzzle/xml/layoutliterals.h +++ b/src/app/puzzle/xml/vplayoutliterals.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file literals.h + ** @file vplayoutliterals.h ** @author Roman Telezhynskyi ** @date 23 4, 2020 ** @@ -25,8 +25,8 @@ ** along with Valentina. If not, see . ** *************************************************************************/ -#ifndef LAYOUTLITERALS_H -#define LAYOUTLITERALS_H +#ifndef VPLAYOUTLITERALS_H +#define VPLAYOUTLITERALS_H #include @@ -36,16 +36,18 @@ namespace ML { extern const QString TagLayout; extern const QString TagProperties; -extern const QString TagLayers; +extern const QString TagPieceLists; extern const QString TagUnit; extern const QString TagDescription; extern const QString TagSize; extern const QString TagMargin; extern const QString TagControl; extern const QString TagTiles; -extern const QString TagUnplacedPiecesLayer; -extern const QString TagLayer; +extern const QString TagUnplacedPieceList; +extern const QString TagPieceList; extern const QString TagPiece; +extern const QString TagSheets; +extern const QString TagSheet; extern const QString AttrVersion; extern const QString AttrWarningSuperposition; @@ -69,4 +71,4 @@ extern const QString AttrShowSeamline; } -#endif // LAYOUTLITERALS_H +#endif // VPLAYOUTLITERALS_H