146 #include <QVBoxLayout>
147 #include <QListWidgetItem>
151 #include <KActionCollection>
152 #include <KConfigDialog>
153 #include <KFileDialog>
154 #include <KGlobalSettings>
155 #include <KIO/NetAccess>
157 #include <KMessageBox>
158 #include <KRecentFilesAction>
159 #include <KStatusBar>
160 #include <KTabWidget>
169 #include "ui_EditorConfigPage.h"
171 #include "SymbolEditor.h"
187 : m_tabWidget(new KTabWidget(this)),
195 m_url = KUrl(i18n(
"Untitled"));
197 setObjectName(
"MainWindow#");
199 KActionCollection *actions = actionCollection();
201 QVBoxLayout *editorLayout =
new QVBoxLayout;
202 editorLayout->addWidget(
m_editor, 0, Qt::AlignCenter);
203 QWidget *layoutWidget =
new QWidget;
204 layoutWidget->setLayout(editorLayout);
207 m_listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
219 connect(
m_editor, SIGNAL(message(QString)), statusBar(), SLOT(showMessage(QString)));
220 connect(
m_editor, SIGNAL(minLineWidth(
bool)), actions->action(
"decreaseLineWidth"), SLOT(setDisabled(
bool)));
221 connect(
m_editor, SIGNAL(maxLineWidth(
bool)), actions->action(
"increaseLineWidth"), SLOT(setDisabled(
bool)));
222 connect(&
m_undoGroup, SIGNAL(canUndoChanged(
bool)), actions->action(
"edit_undo"), SLOT(setEnabled(
bool)));
223 connect(&
m_undoGroup, SIGNAL(canRedoChanged(
bool)), actions->action(
"edit_redo"), SLOT(setEnabled(
bool)));
233 setupGUI(KXmlGuiWindow::Default,
"SymbolEditorui.rc");
237 actions->action(
"moveTo")->trigger();
238 actions->action(
"enableSnap")->setChecked(
true);
239 actions->action(
"file_save")->setEnabled(
false);
240 actions->action(
"saveSymbol")->setEnabled(
false);
241 actions->action(
"saveSymbolAsNew")->setEnabled(
false);
242 actions->action(
"help_contents")->setVisible(
false);
280 int messageBoxResult = KMessageBox::warningYesNoCancel(
this, i18n(
"Save changes to the symbol?\nSelecting No discards changes."));
282 switch (messageBoxResult) {
283 case KMessageBox::Yes:
289 case KMessageBox::No:
293 case KMessageBox::Cancel:
313 int messageBoxResult = KMessageBox::warningYesNoCancel(
this, i18n(
"Save changes to the library?\nSelecting No discards changes."));
315 switch (messageBoxResult) {
316 case KMessageBox::Yes:
321 case KMessageBox::No:
325 case KMessageBox::Cancel:
352 KUrl url = KFileDialog::getOpenUrl(KUrl(
"kfiledialog:///"), i18n(
"*.sym|Cross Stitch Symbols"),
this);
354 if (!url.isEmpty()) {
382 if (KIO::NetAccess::download(url, src, 0)) {
385 if (file.open(QIODevice::ReadOnly)) {
386 QDataStream stream(&file);
391 KRecentFilesAction *action =
static_cast<KRecentFilesAction *
>(actionCollection()->action(
"file_open_recent"));
393 action->saveEntries(KConfigGroup(KGlobal::config(),
"RecentFiles"));
396 KMessageBox::sorry(0, i18n(
"This doesn't appear to be a valid symbol file"));
398 KMessageBox::sorry(0, i18n(
"Version %1 of the library file is not supported in this version of SymbolEditor", e.
version));
400 KMessageBox::sorry(0, i18n(
"Version %1 of the symbol is not supported in this version of SymbolEditor", e.
version));
402 KMessageBox::sorry(0, i18n(
"Failed to read the library\n%1", e.
statusMessage()));
408 KMessageBox::sorry(0, i18n(
"Failed to open the file %1", url.fileName()));
411 KMessageBox::sorry(0, i18n(
"Failed to download the file %1", url.fileName()));
414 KMessageBox::sorry(0, i18n(
"The url %1 is invalid", url.fileName()));
427 if (
m_url == KUrl(i18n(
"Untitled"))) {
430 QFile file(
m_url.path());
432 if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
433 QDataStream stream(&file);
434 stream.setVersion(QDataStream::Qt_4_0);
439 KMessageBox::sorry(0, i18n(
"Failed to write the library\n%1", e.
statusMessage()));
445 KMessageBox::sorry(0, i18n(
"Failed to open the file %1\n%2",
m_url.fileName(), file.errorString()));
458 KUrl url = KFileDialog::getSaveUrl(QString(
"::%1").arg(KGlobalSettings::documentPath()), i18n(
"*.sym|Cross Stitch Symbols"),
this, i18n(
"Save As"));
461 if (KIO::NetAccess::exists(url,
false, 0)) {
462 if (KMessageBox::warningYesNo(
this, i18n(
"This file already exists\nDo you want to overwrite it?")) == KMessageBox::No) {
469 KRecentFilesAction *action =
static_cast<KRecentFilesAction *
>(actionCollection()->action(
"file_open_recent"));
471 action->saveEntries(KConfigGroup(KGlobal::config(),
"RecentFiles"));
488 actionCollection()->action(
"moveTo")->trigger();
534 KUrl url = KFileDialog::getOpenUrl(KUrl(
"kfiledialog:///"), i18n(
"*.sym|Cross Stitch Symbols"),
this);
543 if (KIO::NetAccess::download(url, src, 0)) {
546 if (file.open(QIODevice::ReadOnly)) {
548 QDataStream stream(&file);
554 KMessageBox::sorry(0, i18n(
"This doesn't appear to be a valid symbol file"));
556 KMessageBox::sorry(0, i18n(
"Version %1 of the library file is not supported in this version of SymbolEditor", e.
version));
561 KMessageBox::sorry(0, i18n(
"Failed to open the file %1", url.fileName()));
564 KMessageBox::sorry(0, i18n(
"Failed to download the file %1", url.fileName()));
567 KMessageBox::sorry(0, i18n(
"The url %1 is invalid", url.fileName()));
582 m_url = KUrl(i18n(
"Untitled"));
593 KXmlGuiWindow::close();
628 actionCollection()->action(
"edit_undo")->setText(QString(i18n(
"Undo %1", text)));
641 actionCollection()->action(
"edit_redo")->setText(QString(i18n(
"Redo %1", text)));
652 QString tab = QString(
"%1 ").arg(
m_url.fileName());
655 tab += QString(i18nc(
"The Library tab title",
"Library"));
657 tab += QString(i18nc(
"The Editor tab title",
"Editor"));
660 setCaption(tab, !clean);
675 }
else if (index == 1) {
692 QPair<qint16, Symbol> pair;
696 pair.first =
static_cast<qint16
>(item->data(Qt::UserRole).toInt());
720 m_menu->popup(QCursor::pos());
740 if (KConfigDialog::showDialog(
"preferences")) {
744 KConfigDialog *dialog =
new KConfigDialog(
this,
"preferences", Configuration::self());
745 dialog->setFaceType(KPageDialog::List);
747 dialog->addPage(
new EditorConfigPage(0,
"EditorConfigPage"), i18nc(
"The Editor config page",
"Editor"),
"preferences-desktop");
749 connect(dialog, SIGNAL(settingsChanged(QString)),
m_editor, SLOT(readSettings()));
765 QActionGroup *actionGroup;
767 KActionCollection *actions = actionCollection();
770 KStandardAction::open(
this, SLOT(
fileOpen()), actions);
771 KStandardAction::openNew(
this, SLOT(
newSymbol()), actions);
772 KStandardAction::openRecent(
this, SLOT(
fileOpen(KUrl)), actions)->loadEntries(KConfigGroup(KGlobal::config(),
"RecentFiles"));
773 KStandardAction::save(
this, SLOT(
save()), actions);
774 KStandardAction::saveAs(
this, SLOT(
saveAs()), actions);
776 action =
new KAction(
this);
777 action->setText(i18n(
"Import Library"));
778 connect(action, SIGNAL(triggered()),
this, SLOT(
importLibrary()));
779 actions->addAction(
"importLibrary", action);
781 action =
new KAction(
this);
782 action->setText(i18n(
"Save Symbol"));
783 action->setIcon(KIcon(
"save-symbol"));
784 connect(action, SIGNAL(triggered()),
this, SLOT(
saveSymbol()));
785 actions->addAction(
"saveSymbol", action);
787 action =
new KAction(
this);
788 action->setText(i18n(
"Save Symbol as New"));
790 actions->addAction(
"saveSymbolAsNew", action);
792 KStandardAction::close(
this, SLOT(
close()), actions);
793 KStandardAction::quit(
this, SLOT(
quit()), actions);
796 KStandardAction::undo(
this, SLOT(
undo()), actions);
797 KStandardAction::redo(
this, SLOT(
redo()), actions);
800 action =
new KAction(
this);
801 action->setText(i18n(
"Fill Path"));
802 action->setIcon(KIcon(
"rating"));
803 action->setCheckable(
true);
804 connect(action, SIGNAL(triggered(
bool)),
m_editor, SLOT(selectFilled(
bool)));
805 actions->addAction(
"fillPath", action);
807 actionGroup =
new QActionGroup(
this);
808 actionGroup->setExclusive(
true);
810 action =
new KAction(
this);
811 action->setText(i18n(
"Odd Even Fill"));
812 action->setData(Qt::OddEvenFill);
813 action->setIcon(KIcon(
"odd-even-fill"));
814 action->setCheckable(
true);
815 actions->addAction(
"oddEvenFill", action);
816 actionGroup->addAction(action);
818 action =
new KAction(
this);
819 action->setText(i18n(
"Winding Fill"));
820 action->setData(Qt::WindingFill);
821 action->setIcon(KIcon(
"winding-fill"));
822 action->setCheckable(
true);
823 actions->addAction(
"windingFill", action);
824 actionGroup->addAction(action);
826 connect(actionGroup, SIGNAL(triggered(QAction*)),
m_editor, SLOT(selectFillRule(QAction*)));
828 actionGroup =
new QActionGroup(
this);
829 actionGroup->setExclusive(
true);
831 action =
new KAction(
this);
832 action->setText(i18n(
"Flat Cap"));
833 action->setData(Qt::FlatCap);
834 action->setIcon(KIcon(
"flat-cap"));
835 action->setCheckable(
true);
836 actions->addAction(
"flatCap", action);
837 actionGroup->addAction(action);
839 action =
new KAction(
this);
840 action->setText(i18n(
"Square Cap"));
841 action->setData(Qt::SquareCap);
842 action->setIcon(KIcon(
"square-cap"));
843 action->setCheckable(
true);
844 actions->addAction(
"squareCap", action);
845 actionGroup->addAction(action);
847 action =
new KAction(
this);
848 action->setText(i18n(
"Round Cap"));
849 action->setData(Qt::RoundCap);
850 action->setIcon(KIcon(
"round-cap"));
851 action->setCheckable(
true);
852 actions->addAction(
"roundCap", action);
853 actionGroup->addAction(action);
855 connect(actionGroup, SIGNAL(triggered(QAction*)),
m_editor, SLOT(selectCapStyle(QAction*)));
857 actionGroup =
new QActionGroup(
this);
858 actionGroup->setExclusive(
true);
860 action =
new KAction(
this);
861 action->setText(i18n(
"Bevel Join"));
862 action->setData(Qt::BevelJoin);
863 action->setIcon(KIcon(
"bevel-join"));
864 action->setCheckable(
true);
865 actions->addAction(
"bevelJoin", action);
866 actionGroup->addAction(action);
868 action =
new KAction(
this);
869 action->setText(i18n(
"Miter Join"));
870 action->setData(Qt::MiterJoin);
871 action->setIcon(KIcon(
"miter-join"));
872 action->setCheckable(
true);
873 actions->addAction(
"miterJoin", action);
874 actionGroup->addAction(action);
876 action =
new KAction(
this);
877 action->setText(i18n(
"Round Join"));
878 action->setData(Qt::RoundJoin);
879 action->setIcon(KIcon(
"round-join"));
880 action->setCheckable(
true);
881 actions->addAction(
"roundJoin", action);
882 actionGroup->addAction(action);
884 connect(actionGroup, SIGNAL(triggered(QAction*)),
m_editor, SLOT(selectJoinStyle(QAction*)));
886 action =
new KAction(
this);
887 action->setText(i18n(
"Increase Line Width"));
888 action->setIcon(KIcon(
"increase-line-width"));
889 connect(action, SIGNAL(triggered()),
m_editor, SLOT(increaseLineWidth()));
890 actions->addAction(
"increaseLineWidth", action);
892 action =
new KAction(
this);
893 action->setText(i18n(
"Decrease Line Width"));
894 action->setIcon(KIcon(
"decrease-line-width"));
895 connect(action, SIGNAL(triggered()),
m_editor, SLOT(decreaseLineWidth()));
896 actions->addAction(
"decreaseLineWidth", action);
899 actionGroup =
new QActionGroup(
this);
900 actionGroup->setExclusive(
true);
902 action =
new KAction(
this);
903 action->setText(i18n(
"Move To"));
905 action->setIcon(KIcon(
"go-jump"));
906 action->setCheckable(
true);
907 actions->addAction(
"moveTo", action);
908 actionGroup->addAction(action);
910 action =
new KAction(
this);
911 action->setText(i18n(
"Draw To"));
913 action->setIcon(KIcon(
"draw-line"));
914 action->setCheckable(
true);
915 actions->addAction(
"lineTo", action);
916 actionGroup->addAction(action);
918 action =
new KAction(
this);
919 action->setText(i18n(
"Cubic To"));
921 action->setIcon(KIcon(
"draw-bezier-curves"));
922 action->setCheckable(
true);
923 actions->addAction(
"cubicTo", action);
924 actionGroup->addAction(action);
926 action =
new KAction(
this);
927 action->setText(i18n(
"Rectangle"));
929 action->setIcon(KIcon(
"draw-rectangle"));
930 action->setCheckable(
true);
931 actions->addAction(
"rectangle", action);
932 actionGroup->addAction(action);
934 action =
new KAction(
this);
935 action->setText(i18n(
"Ellipse"));
937 action->setIcon(KIcon(
"draw-ellipse"));
938 action->setCheckable(
true);
939 actions->addAction(
"ellipse", action);
940 actionGroup->addAction(action);
942 action =
new KAction(
this);
943 action->setText(i18n(
"Insert Character"));
945 action->setIcon(KIcon(
"character-set"));
946 action->setCheckable(
true);
947 actions->addAction(
"character", action);
948 actionGroup->addAction(action);
950 connect(actionGroup, SIGNAL(triggered(QAction*)),
m_editor, SLOT(selectTool(QAction*)));
952 action =
new KAction(
this);
953 action->setText(i18n(
"Rotate Left"));
954 action->setIcon(KIcon(
"object-rotate-left"));
955 connect(action, SIGNAL(triggered()),
m_editor, SLOT(rotateLeft()));
956 actions->addAction(
"rotateLeft", action);
958 action =
new KAction(
this);
959 action->setText(i18n(
"Rotate Right"));
960 action->setIcon(KIcon(
"object-rotate-right"));
961 connect(action, SIGNAL(triggered()),
m_editor, SLOT(rotateRight()));
962 actions->addAction(
"rotateRight", action);
964 action =
new KAction(
this);
965 action->setText(i18n(
"Flip Horizontal"));
966 action->setIcon(KIcon(
"object-flip-horizontal"));
967 connect(action, SIGNAL(triggered()),
m_editor, SLOT(flipHorizontal()));
968 actions->addAction(
"flipHorizontal", action);
970 action =
new KAction(
this);
971 action->setText(i18n(
"Flip Vertical"));
972 action->setIcon(KIcon(
"object-flip-vertical"));
973 connect(action, SIGNAL(triggered()),
m_editor, SLOT(flipVertical()));
974 actions->addAction(
"flipVertical", action);
976 action =
new KAction(
this);
977 action->setText(i18n(
"Scale to Preferred Size"));
978 action->setIcon(KIcon(
"scale-preferred"));
979 connect(action, SIGNAL(triggered()),
m_editor, SLOT(scalePreferred()));
980 actions->addAction(
"scalePreferred", action);
982 action =
new KAction(
this);
983 action->setText(i18n(
"Enable Snap"));
984 action->setIcon(KIcon(
"snap-to-grid"));
985 action->setCheckable(
true);
986 connect(action, SIGNAL(toggled(
bool)),
m_editor, SLOT(enableSnap(
bool)));
987 actions->addAction(
"enableSnap", action);
990 KStandardAction::preferences(
this, SLOT(
preferences()), actions);
1001 action(
"fillPath")->setChecked(symbol.
filled());
1003 switch (symbol.
path().fillRule()) {
1004 case Qt::WindingFill:
1005 action(
"windingFill")->setChecked(
true);
1008 case Qt::OddEvenFill:
1009 action(
"oddEvenFill")->setChecked(
true);
1015 action(
"flatCap")->setChecked(
true);
1019 action(
"squareCap")->setChecked(
true);
1023 action(
"roundCap")->setChecked(
true);
1029 action(
"bevelJoin")->setChecked(
true);
1033 action(
"miterJoin")->setChecked(
true);
1037 action(
"roundJoin")->setChecked(
true);
1041 action(
"increaseLineWidth")->setDisabled(symbol.
lineWidth() == 1.00);
1042 action(
"decreaseLineWidth")->setDisabled(symbol.
lineWidth() == 0.01);