diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a7c9af..69723da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,106 +1,108 @@ project(kimagemapeditor) cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR) set (QT_MIN_VERSION "5.7.0") set (KF5_MIN_VERSION "5.15.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED CONFIG) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) +add_compile_definitions(QURL_NO_CAST_FROM_STRING) + find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Gui Widgets ) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Config ConfigWidgets CoreAddons Crash DBusAddons DocTools GuiAddons IconThemes KHtml Parts I18n WidgetsAddons XmlGui ) include(FeatureSummary) include(ECMInstallIcons) include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(ECMOptionalAddSubdirectory) include(ECMQtDeclareLoggingCategory) include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ) add_subdirectory( pics ) ecm_optional_add_subdirectory(doc) set(libkimagemapeditorcommon_SRC areacreator.cpp kimearea.cpp kimecommands.cpp kimedialogs.cpp kimagemapeditor.cpp drawzone.cpp arealistview.cpp imageslistview.cpp mapslistview.cpp imagemapchoosedialog.cpp ) ecm_qt_declare_logging_category(libkimagemapeditorcommon_SRC HEADER kimagemapeditor_debug.h IDENTIFIER KIMAGEMAPEDITOR_LOG CATEGORY_NAME org.kde.kimagemapeditor DEFAULT_SEVERITY Warning ) ########### next target ############### set(kimagemapeditor_bin_SRCS main.cpp kimeshell.cpp ${libkimagemapeditorcommon_SRC}) add_executable(kimagemapeditor_bin ${kimagemapeditor_bin_SRCS}) set_target_properties(kimagemapeditor_bin PROPERTIES OUTPUT_NAME kimagemapeditor) target_link_libraries(kimagemapeditor_bin KF5::KHtml KF5::IconThemes) install(TARGETS kimagemapeditor_bin ${INSTALL_TARGETS_DEFAULT_ARGS} ) ########### next target ############### set(kimagemapeditor_PART_SRCS ${libkimagemapeditorcommon_SRC}) add_library(kimagemapeditor MODULE ${kimagemapeditor_PART_SRCS}) target_link_libraries(kimagemapeditor KF5::KHtml KF5::IconThemes) install(TARGETS kimagemapeditor DESTINATION ${PLUGIN_INSTALL_DIR}) ########### next target ############### ########### install files ############### install( FILES org.kde.kimagemapeditor.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install( FILES org.kde.kimagemapeditor.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) install( FILES kimagemapeditorpart.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) install( FILES kimagemapeditorui.rc kimagemapeditorpartui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/kimagemapeditor) if (NOT ECM_VERSION VERSION_LESS "5.59.0") install( FILES kimagemapeditor.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR} ) else() install( FILES kimagemapeditor.categories DESTINATION ${KDE_INSTALL_CONFDIR} ) endif() feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/kimagemapeditor.cpp b/kimagemapeditor.cpp index 08a7d66..0f9f426 100644 --- a/kimagemapeditor.cpp +++ b/kimagemapeditor.cpp @@ -1,2903 +1,2903 @@ /*************************************************************************** imagemapeditor.cpp - description ------------------- begin : Wed Apr 4 2001 copyright : (C) 2001 by Jan Schäfer email : j_schaef@informatik.uni-kl.de ***************************************************************************/ /*************************************************************************** * * * This program 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 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "kimagemapeditor.h" #include #include // Qt #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // KDE Frameworks #include "kimagemapeditor_debug.h" #include #include #include #include #include #include #include #include #include #include #include // local #include "drawzone.h" #include "kimedialogs.h" #include "kimecommands.h" #include "areacreator.h" #include "arealistview.h" #include "imageslistview.h" #include "mapslistview.h" #include "kimecommon.h" #include "imagemapchoosedialog.h" #include "version.h" K_PLUGIN_FACTORY(KImageMapEditorFactory, registerPlugin();) KImageMapEditor::KImageMapEditor(QWidget *parentWidget, QObject *parent, const QVariantList & ) : KParts::ReadWritePart(parent) { KAboutData aboutData( "kimagemapeditor", i18n("KImageMapEditor"), KIMAGEMAPEDITOR_VERSION, i18n( "An HTML imagemap editor" ), KAboutLicense::GPL, i18n("(c) 2001-2003 Jan Schäfer janschaefer@users.sourceforge.net")); setComponentData(aboutData, false); // KDockMainWindow* mainWidget; mainWindow = dynamic_cast(parent) ; QSplitter * splitter = 0L; tabWidget = 0L; if (mainWindow) { // qCDebug(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor: We got a KDockMainWindow !"; // K3DockWidget* parentDock = mainDock->getMainDockWidget(); areaDock = new QDockWidget(i18n("Areas"),mainWindow); mapsDock = new QDockWidget(i18n("Maps"),mainWindow); imagesDock = new QDockWidget(i18n("Images"),mainWindow); // Needed to save their state areaDock->setObjectName("areaDock"); mapsDock->setObjectName("mapsDock"); imagesDock->setObjectName("imagesDock"); mainWindow->addDockWidget( Qt::LeftDockWidgetArea, areaDock); mainWindow->addDockWidget( Qt::LeftDockWidgetArea, mapsDock); mainWindow->addDockWidget( Qt::LeftDockWidgetArea, imagesDock); areaListView = new AreaListView(areaDock); mapsListView = new MapsListView(mapsDock); imagesListView = new ImagesListView(imagesDock); areaDock->setWidget(areaListView); mapsDock->setWidget(mapsListView); imagesDock->setWidget(imagesListView); } else { areaDock = 0L; mapsDock = 0L; imagesDock = 0L; splitter = new QSplitter(parentWidget); tabWidget = new QTabWidget(splitter); areaListView = new AreaListView(tabWidget); mapsListView = new MapsListView(tabWidget); imagesListView = new ImagesListView(tabWidget); tabWidget->addTab(areaListView,i18n("Areas")); tabWidget->addTab(mapsListView,i18n("Maps")); tabWidget->addTab(imagesListView,i18n("Images")); } connect( areaListView->listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged())); connect( areaListView->listView, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(showTagEditor(QTreeWidgetItem*))); connect( areaListView->listView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotShowPopupMenu(QPoint))); connect( mapsListView, SIGNAL(mapSelected(QString)), this, SLOT(setMap(QString))); connect( mapsListView, SIGNAL(mapRenamed(QString)), this, SLOT(setMapName(QString))); connect( mapsListView->listView(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotShowMapPopupMenu(QPoint))); connect( imagesListView, &ImagesListView::imageSelected, this, QOverload::of(&KImageMapEditor::setPicture)); connect( imagesListView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotShowImagePopupMenu(QPoint))); if (splitter) { drawZone = new DrawZone(splitter,this); splitter->setStretchFactor(splitter->indexOf(tabWidget), 0); splitter->setStretchFactor(splitter->indexOf(drawZone), 1); setWidget(splitter); } else { QScrollArea *sa = new QScrollArea(mainWindow); drawZone = new DrawZone(0L,this); mainWindow->setCentralWidget(sa); sa->setWidget(drawZone); setWidget(mainWindow); // sa->setWidgetResizable(true); } areas = new AreaList(); currentSelected= new AreaSelection(); _currentToolType=KImageMapEditor::Selection; copyArea=0L; defaultArea=0L; currentMapElement = 0L; setupActions(); setupStatusBar(); setXMLFile("kimagemapeditorpartui.rc"); setPicture(getBackgroundImage()); init(); readConfig(); } KImageMapEditor::~KImageMapEditor() { writeConfig(); delete areas; delete currentSelected; delete copyArea; delete defaultArea; // Delete our DockWidgets if (areaDock) { areaDock->hide(); mapsDock->hide(); imagesDock->hide(); delete areaDock; delete mapsDock; delete imagesDock; } } MapTag::MapTag() { modified = false; name.clear(); } void KImageMapEditor::init() { _htmlContent.clear(); _imageUrl.clear(); // closeUrl(); HtmlElement* el = new HtmlElement("\n"); _htmlContent.append(el); el = new HtmlElement("\n"); _htmlContent.append(el); el = new HtmlElement("\n"); _htmlContent.append(el); el = new HtmlElement("\n"); _htmlContent.append(el); addMap(i18n("unnamed")); el = new HtmlElement("\n"); _htmlContent.append(el); el = new HtmlElement("\n"); _htmlContent.append(el); setImageActionsEnabled(false); } void KImageMapEditor::setReadWrite(bool) { // For now it does not matter if it is readwrite or readonly // it is always readwrite, because Quanta only supports ReadOnlyParts // at this moment and in that case it should be readwrite, too. ReadWritePart::setReadWrite(true); /* if (rw) ; else { actionCollection()->remove(arrowAction); actionCollection()->remove(circleAction); actionCollection()->remove(rectangleAction); actionCollection()->remove(polygonAction); actionCollection()->remove(freehandAction); actionCollection()->remove(addPointAction); actionCollection()->remove(removePointAction); actionCollection()->remove(cutAction); actionCollection()->remove(deleteAction); actionCollection()->remove(copyAction); actionCollection()->remove(pasteAction); actionCollection()->remove(mapNewAction); actionCollection()->remove(mapDeleteAction); actionCollection()->remove(mapNameAction); actionCollection()->remove(mapDefaultAreaAction); actionCollection()->remove(areaPropertiesAction); actionCollection()->remove(moveLeftAction); actionCollection()->remove(moveRightAction); actionCollection()->remove(moveUpAction); actionCollection()->remove(moveDownAction); actionCollection()->remove(increaseWidthAction); actionCollection()->remove(decreaseWidthAction); actionCollection()->remove(increaseHeightAction); actionCollection()->remove(decreaseHeightAction); actionCollection()->remove(toFrontAction); actionCollection()->remove(toBackAction); actionCollection()->remove(forwardOneAction); actionCollection()->remove(backOneAction); actionCollection()->remove(imageRemoveAction); actionCollection()->remove(imageAddAction); actionCollection()->remove(imageUsemapAction); } */ } void KImageMapEditor::setModified(bool modified) { // get a handle on our Save action and make sure it is valid QAction *save = actionCollection()->action(KStandardAction::name(KStandardAction::Save)); if (!save) return; // if so, we either enable or disable it based on the current // state if (modified) save->setEnabled(true); else save->setEnabled(false); // in any event, we want our parent to do it's thing ReadWritePart::setModified(modified); } KConfig *KImageMapEditor::config() { /* TODO KF5 KSharedConfigPtr tmp = KimeFactory::componentData().config(); return tmp.data(); */ return new KConfig(); } void KImageMapEditor::readConfig(const KConfigGroup &config) { KConfigGroup data = config.parent().group( "Data" ); recentFilesAction->loadEntries( data ); } void KImageMapEditor::writeConfig(KConfigGroup& config) { config.writeEntry("highlightareas",highlightAreasAction->isChecked()); config.writeEntry("showalt",showAltAction->isChecked()); KConfigGroup data = config.parent().group( "Data" ); recentFilesAction->saveEntries( data ); saveLastURL(config); } void KImageMapEditor::readConfig() { readConfig(config()->group("General Options" ) ); slotConfigChanged(); } void KImageMapEditor::writeConfig() { KConfigGroup cg( config(), "General Options"); writeConfig( cg ); config()->sync(); } void KImageMapEditor::saveProperties(KConfigGroup &config) { saveLastURL(config); } void KImageMapEditor::readProperties(const KConfigGroup& config) { openLastURL(config); } void KImageMapEditor::slotConfigChanged() { KConfigGroup group = config()->group("Appearance"); int newHeight=group.readEntry("maximum-preview-height",50); group = config()->group("General Options"); _commandHistory->setUndoLimit(group.readEntry("undo-level",100)); #if 0 _commandHistory->setRedoLimit(group.readEntry("redo-level",100)); #endif Area::highlightArea = group.readEntry("highlightareas",true); highlightAreasAction->setChecked(Area::highlightArea); Area::showAlt = group.readEntry("showalt",true); showAltAction->setChecked(Area::showAlt); // if the image preview size changed update all images if (maxAreaPreviewHeight!=newHeight) { maxAreaPreviewHeight=newHeight; areaListView->listView->setIconSize(QSize(newHeight,newHeight)); } updateAllAreas(); drawZone->repaint(); } void KImageMapEditor::openLastURL(const KConfigGroup & config) { QUrl lastURL ( config.readPathEntry("lastopenurl", QString()) ); QString lastMap = config.readEntry("lastactivemap"); QString lastImage = config.readPathEntry("lastactiveimage", QString()); // qCDebug(KIMAGEMAPEDITOR_LOG) << "loading from group : " << config.group(); // qCDebug(KIMAGEMAPEDITOR_LOG) << "loading entry lastopenurl : " << lastURL.path(); // KMessageBox::information(0L, config.group()+" "+lastURL.path()); if (!lastURL.isEmpty()) { openUrl(lastURL); if (!lastMap.isEmpty()) mapsListView->selectMap(lastMap); if (!lastImage.isEmpty()) - setPicture(lastImage); + setPicture(QUrl::fromLocalFile(lastImage)); // qCDebug(KIMAGEMAPEDITOR_LOG) << "opening HTML file with map " << lastMap << " and image " << lastImage; // if (! openHTMLFile(lastURL, lastMap, lastImage) ) // closeUrl(); //openUrl(lastURL); // else //closeUrl(); } } void KImageMapEditor::saveLastURL(KConfigGroup & config) { qCDebug(KIMAGEMAPEDITOR_LOG) << "saveLastURL: " << url().path(); config.writePathEntry("lastopenurl",url().path()); config.writeEntry("lastactivemap",mapName()); config.writePathEntry("lastactiveimage",_imageUrl.path()); // qCDebug(KIMAGEMAPEDITOR_LOG) << "writing entry lastopenurl : " << url().path(); // qCDebug(KIMAGEMAPEDITOR_LOG) << "writing entry lastactivemap : " << mapName(); // qCDebug(KIMAGEMAPEDITOR_LOG) << "writing entry lastactiveimage : " << _imageUrl.path(); //KMessageBox::information(0L, QString("Group: %1 Saving ... %2").arg(config.group()).arg(url().path())); } void KImageMapEditor::setupActions() { // File Open QAction *temp = KStandardAction::open(this, SLOT(fileOpen()), actionCollection()); temp->setWhatsThis(i18n("

Open File

Click this to open a new picture or HTML file.")); temp->setToolTip(i18n("Open new picture or HTML file")); // File Open Recent recentFilesAction = KStandardAction::openRecent(this, SLOT(openURL(QUrl)), actionCollection()); // File Save temp =KStandardAction::save(this, SLOT(fileSave()), actionCollection()); temp->setWhatsThis(i18n("

Save File

Click this to save the changes to the HTML file.")); temp->setToolTip(i18n("Save HTML file")); // File Save As (void)KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection()); // File Close temp=KStandardAction::close(this, SLOT(fileClose()), actionCollection()); temp->setWhatsThis(i18n("

Close File

Click this to close the currently open HTML file.")); temp->setToolTip(i18n("Close HTML file")); // Edit Copy copyAction=KStandardAction::copy(this, SLOT(slotCopy()), actionCollection()); copyAction->setWhatsThis(i18n("

Copy

" "Click this to copy the selected area.")); copyAction->setEnabled(false); // Edit Cut cutAction=KStandardAction::cut(this, SLOT(slotCut()), actionCollection()); cutAction->setWhatsThis(i18n("

Cut

" "Click this to cut the selected area.")); cutAction->setEnabled(false); // Edit Paste pasteAction=KStandardAction::paste(this, SLOT(slotPaste()), actionCollection()); pasteAction->setWhatsThis(i18n("

Paste

" "Click this to paste the copied area.")); pasteAction->setEnabled(false); // Edit Delete deleteAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("&Delete"), this); actionCollection()->addAction("edit_delete", deleteAction ); connect(deleteAction, SIGNAL(triggered(bool)), SLOT (slotDelete())); actionCollection()->setDefaultShortcut(deleteAction, QKeySequence(Qt::Key_Delete)); deleteAction->setWhatsThis(i18n("

Delete

" "Click this to delete the selected area.")); deleteAction->setEnabled(false); // Edit Undo/Redo _commandHistory = new QUndoStack(this); KUndoActions::createUndoAction(_commandHistory, actionCollection()); KUndoActions::createRedoAction(_commandHistory, actionCollection()); // Edit Properties areaPropertiesAction = new QAction(i18n("Pr&operties"), this); actionCollection()->addAction("edit_properties", areaPropertiesAction ); connect(areaPropertiesAction, SIGNAL(triggered(bool)), SLOT(showTagEditor())); areaPropertiesAction->setEnabled(false); // View Zoom In zoomInAction=KStandardAction::zoomIn(this, SLOT(slotZoomIn()), actionCollection()); // View Zoom Out zoomOutAction=KStandardAction::zoomOut(this, SLOT(slotZoomOut()), actionCollection()); // View Zoom zoomAction = new KSelectAction(i18n("Zoom"), this); actionCollection()->addAction("view_zoom", zoomAction ); connect(zoomAction, SIGNAL(triggered(int)), this, SLOT (slotZoom())); zoomAction->setWhatsThis(i18n("

Zoom

" "Choose the desired zoom level.")); zoomAction->setItems(QStringList() << i18n("25%") << i18n("50%") << i18n("100%") << i18n("150%") << i18n("200%") << i18n("250%") << i18n("300%") << i18n("500%") << i18n("750%") << i18n("1000%")); zoomAction->setCurrentItem(2); highlightAreasAction = actionCollection()->add("view_highlightareas"); highlightAreasAction->setText(i18n("Highlight Areas")); connect(highlightAreasAction, SIGNAL(toggled(bool)), this, SLOT(slotHighlightAreas(bool))); showAltAction = actionCollection()->add("view_showalt"); showAltAction->setText(i18n("Show Alt Tag")); connect(showAltAction, SIGNAL(toggled(bool)),this, SLOT (slotShowAltTag(bool))); mapNameAction = new QAction(i18n("Map &Name..."), this); actionCollection()->addAction("map_name", mapNameAction ); connect(mapNameAction, SIGNAL(triggered(bool)), SLOT(mapEditName())); mapNewAction = new QAction(i18n("Ne&w Map..."), this); actionCollection()->addAction("map_new", mapNewAction ); connect(mapNewAction, SIGNAL(triggered(bool)), SLOT(mapNew())); mapNewAction->setToolTip(i18n("Create a new map")); mapDeleteAction = new QAction(i18n("D&elete Map"), this); actionCollection()->addAction("map_delete", mapDeleteAction ); connect(mapDeleteAction, SIGNAL(triggered(bool)), SLOT(mapDelete())); mapDeleteAction->setToolTip(i18n("Delete the current active map")); mapDefaultAreaAction = new QAction(i18n("Edit &Default Area..."), this); actionCollection()->addAction("map_defaultarea", mapDefaultAreaAction ); connect(mapDefaultAreaAction, SIGNAL(triggered(bool)), SLOT(mapDefaultArea())); mapDefaultAreaAction->setToolTip(i18n("Edit the default area of the current active map")); temp = new QAction(i18n("&Preview"), this); actionCollection()->addAction("map_preview", temp ); connect(temp, SIGNAL(triggered(bool)), SLOT(mapPreview())); temp->setToolTip(i18n("Show a preview")); // IMAGE i18n("&Image"); imageAddAction = new QAction(i18n("Add Image..."), this); actionCollection()->addAction("image_add", imageAddAction ); connect(imageAddAction, SIGNAL(triggered(bool)), SLOT(imageAdd())); imageAddAction->setToolTip(i18n("Add a new image")); imageRemoveAction = new QAction(i18n("Remove Image"), this); actionCollection()->addAction("image_remove", imageRemoveAction ); connect(imageRemoveAction, SIGNAL(triggered(bool)), SLOT(imageRemove())); imageRemoveAction->setToolTip(i18n("Remove the current visible image")); imageUsemapAction = new QAction(i18n("Edit Usemap..."), this); actionCollection()->addAction("image_usemap", imageUsemapAction ); connect(imageUsemapAction, SIGNAL(triggered(bool)), SLOT(imageUsemap())); imageUsemapAction->setToolTip(i18n("Edit the usemap tag of the current visible image")); temp = new QAction(i18n("Show &HTML"), this); actionCollection()->addAction("map_showhtml", temp ); connect(temp, SIGNAL(triggered(bool)), SLOT(mapShowHTML())); QActionGroup *drawingGroup = new QActionGroup(this); // Selection Tool arrowAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("arrow")), i18n("&Selection"), this); actionCollection()->setDefaultShortcut(arrowAction, QKeySequence("s")); actionCollection()->addAction("tool_arrow", arrowAction); connect(arrowAction, SIGNAL(triggered(bool)), SLOT (slotDrawArrow())); arrowAction->setWhatsThis(i18n("

Selection

" "Click this to select areas.")); drawingGroup->addAction(arrowAction); arrowAction->setChecked(true); // Circle circleAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("circle")), i18n("&Circle"), this); actionCollection()->setDefaultShortcut(circleAction, QKeySequence("c")); actionCollection()->addAction("tool_circle", circleAction); connect(circleAction, SIGNAL(triggered(bool)), this, SLOT(slotDrawCircle())); circleAction->setWhatsThis(i18n("

Circle

" "Click this to start drawing a circle.")); drawingGroup->addAction(circleAction); // Rectangle rectangleAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("rectangle")), i18n("&Rectangle"), this); actionCollection()->setDefaultShortcut(rectangleAction, QKeySequence("r")); actionCollection()->addAction("tool_rectangle", rectangleAction); connect(rectangleAction, SIGNAL(triggered(bool)), this, SLOT(slotDrawRectangle())); rectangleAction->setWhatsThis(i18n("

Rectangle

" "Click this to start drawing a rectangle.")); drawingGroup->addAction(rectangleAction); // Polygon polygonAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("polygon")), i18n("&Polygon"), this); actionCollection()->setDefaultShortcut(polygonAction, QKeySequence("p")); actionCollection()->addAction("tool_polygon", polygonAction); connect(polygonAction, SIGNAL(triggered(bool)), SLOT(slotDrawPolygon())); polygonAction->setWhatsThis(i18n("

Polygon

" "Click this to start drawing a polygon.")); drawingGroup->addAction(polygonAction); // Freehand freehandAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("freehand")), i18n("&Freehand Polygon"), this); actionCollection()->setDefaultShortcut(freehandAction, QKeySequence("f")); actionCollection()->addAction("tool_freehand", freehandAction); connect(freehandAction, SIGNAL(triggered(bool)), SLOT(slotDrawFreehand())); freehandAction->setWhatsThis(i18n("

Freehandpolygon

" "Click this to start drawing a freehand polygon.")); drawingGroup->addAction(freehandAction); // Add Point addPointAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("addpoint")), i18n("&Add Point"), this); actionCollection()->setDefaultShortcut(addPointAction, QKeySequence("a")); actionCollection()->addAction("tool_addpoint", addPointAction); connect(addPointAction, SIGNAL(triggered(bool)), SLOT(slotDrawAddPoint())); addPointAction->setWhatsThis(i18n("

Add Point

" "Click this to add points to a polygon.")); drawingGroup->addAction(addPointAction); // Remove Point removePointAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("removepoint")), i18n("&Remove Point"), this); actionCollection()->setDefaultShortcut(removePointAction, QKeySequence("e")); actionCollection()->addAction("tool_removepoint", removePointAction); connect(removePointAction, SIGNAL(triggered(bool)), SLOT(slotDrawRemovePoint())); removePointAction->setWhatsThis(i18n("

Remove Point

" "Click this to remove points from a polygon.")); drawingGroup->addAction(removePointAction); QAction *action = new QAction(i18n("Cancel Drawing"), this); actionCollection()->addAction("canceldrawing", action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotCancelDrawing())); actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::Key_Escape)); moveLeftAction = new QAction(i18n("Move Left"), this); actionCollection()->addAction("moveleft", moveLeftAction ); connect(moveLeftAction, SIGNAL(triggered(bool)), SLOT(slotMoveLeft())); actionCollection()->setDefaultShortcut(moveLeftAction, QKeySequence(Qt::Key_Left)); moveRightAction = new QAction(i18n("Move Right"), this); actionCollection()->addAction("moveright", moveRightAction ); connect(moveRightAction, SIGNAL(triggered(bool)), SLOT(slotMoveRight())); actionCollection()->setDefaultShortcut(moveRightAction, QKeySequence(Qt::Key_Right)); moveUpAction = new QAction(i18n("Move Up"), this); actionCollection()->addAction("moveup", moveUpAction ); connect(moveUpAction, SIGNAL(triggered(bool)), SLOT(slotMoveUp())); actionCollection()->setDefaultShortcut(moveUpAction, QKeySequence(Qt::Key_Up)); moveDownAction = new QAction(i18n("Move Down"), this); actionCollection()->addAction("movedown", moveDownAction ); connect(moveDownAction, SIGNAL(triggered(bool)), SLOT(slotMoveDown())); actionCollection()->setDefaultShortcut(moveDownAction, QKeySequence(Qt::Key_Down)); increaseWidthAction = new QAction(i18n("Increase Width"), this); actionCollection()->addAction("increasewidth", increaseWidthAction ); connect(increaseWidthAction, SIGNAL(triggered(bool)), SLOT(slotIncreaseWidth())); actionCollection()->setDefaultShortcut(increaseWidthAction, QKeySequence(Qt::Key_Right + Qt::SHIFT)); decreaseWidthAction = new QAction(i18n("Decrease Width"), this); actionCollection()->addAction("decreasewidth", decreaseWidthAction ); connect(decreaseWidthAction, SIGNAL(triggered(bool)), SLOT(slotDecreaseWidth())); actionCollection()->setDefaultShortcut(decreaseWidthAction, QKeySequence(Qt::Key_Left + Qt::SHIFT)); increaseHeightAction = new QAction(i18n("Increase Height"), this); actionCollection()->addAction("increaseheight", increaseHeightAction ); connect(increaseHeightAction, SIGNAL(triggered(bool)), SLOT(slotIncreaseHeight())); actionCollection()->setDefaultShortcut(increaseHeightAction, QKeySequence(Qt::Key_Up + Qt::SHIFT)); decreaseHeightAction = new QAction(i18n("Decrease Height"), this); actionCollection()->addAction("decreaseheight", decreaseHeightAction ); connect(decreaseHeightAction, SIGNAL(triggered(bool)), SLOT(slotDecreaseHeight())); actionCollection()->setDefaultShortcut(decreaseHeightAction, QKeySequence(Qt::Key_Down + Qt::SHIFT)); toFrontAction = new QAction(i18n("Bring to Front"), this); actionCollection()->addAction("tofront", toFrontAction ); connect(toFrontAction, SIGNAL(triggered(bool)), SLOT(slotToFront())); toBackAction = new QAction(i18n("Send to Back"), this); actionCollection()->addAction("toback", toBackAction ); connect(toBackAction, SIGNAL(triggered(bool)), SLOT(slotToBack())); forwardOneAction = new QAction(QIcon::fromTheme(QStringLiteral("raise")), i18n("Bring Forward One"), this); actionCollection()->addAction("forwardone", forwardOneAction ); connect(forwardOneAction, SIGNAL(triggered(bool)), SLOT(slotForwardOne())); backOneAction = new QAction(QIcon::fromTheme(QStringLiteral("lower")), i18n("Send Back One"), this); actionCollection()->addAction("backone", backOneAction ); connect(backOneAction, SIGNAL(triggered(bool)), SLOT(slotBackOne())); areaListView->upBtn->addAction(forwardOneAction); areaListView->downBtn->addAction(backOneAction); connect( areaListView->upBtn, SIGNAL(pressed()), forwardOneAction, SLOT(trigger())); connect( areaListView->downBtn, SIGNAL(pressed()), backOneAction, SLOT(trigger())); action = new QAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure KImageMapEditor..."), this); actionCollection()->addAction("configure_kimagemapeditor", action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotShowPreferences())); qCDebug(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor: 1"; if (areaDock) { QAction* a = areaDock->toggleViewAction(); a->setText(i18n("Show Area List")); actionCollection()->addAction("configure_show_arealist", a); a = mapsDock->toggleViewAction(); a->setText(i18n("Show Map List")); actionCollection()->addAction("configure_show_maplist", a ); a = imagesDock->toggleViewAction(); a->setText(i18n("Show Image List")); actionCollection()->addAction("configure_show_imagelist", a ); } qCDebug(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor: 2"; updateActionAccess(); qCDebug(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor: 3"; } void KImageMapEditor::setupStatusBar() { // We can't do this with a KPart ! // widget()->statusBar()->insertItem(i18n(" Cursor")+" : x: 0 ,y: 0",STATUS_CURSOR); // widget()->statusBar()->insertItem(i18n(" Selection")+" : - ",STATUS_SELECTION); emit setStatusBarText( i18n(" Selection: - Cursor: x: 0, y: 0 ")); } void KImageMapEditor::slotShowPreferences() { PreferencesDialog *dialog = new PreferencesDialog(widget(),config()); connect(dialog, SIGNAL(preferencesChanged()), this, SLOT(slotConfigChanged())); dialog->exec(); delete dialog; } void KImageMapEditor::showPopupMenu(const QPoint & pos, const QString & name) { QMenu* pop = static_cast(factory()->container(name, this)); if (!pop) { qCWarning(KIMAGEMAPEDITOR_LOG) << QString("KImageMapEditorPart: Missing XML definition for %1\n").arg(name); return; } pop->popup(pos); } void KImageMapEditor::slotShowMainPopupMenu(const QPoint & pos) { showPopupMenu(pos,"popup_main"); } void KImageMapEditor::slotShowMapPopupMenu(const QPoint & pos) { qCDebug(KIMAGEMAPEDITOR_LOG) << "slotShowMapPopupMenu"; QTreeWidgetItem* item = mapsListView->listView()->itemAt(pos); if (isReadWrite()) { mapDeleteAction->setEnabled(item); mapNameAction->setEnabled(item); mapDefaultAreaAction->setEnabled(item); } if (item) mapsListView->selectMap(item); showPopupMenu(mapsListView->listView()->viewport()->mapToGlobal(pos),"popup_map"); } void KImageMapEditor::slotShowImagePopupMenu(const QPoint & pos) { qCDebug(KIMAGEMAPEDITOR_LOG) << "slotShowImagePopupMenu"; QTreeWidgetItem* item = imagesListView->itemAt(pos); imageRemoveAction->setEnabled(item); imageUsemapAction->setEnabled(item); if (item) imagesListView->setCurrentItem(item); showPopupMenu(imagesListView->viewport()->mapToGlobal(pos),"popup_image"); } void KImageMapEditor::slotShowPopupMenu(const QPoint & p) { QTreeWidgetItem* item = areaListView->listView->itemAt(p); if (!item) return; if (!item->isSelected()) { deselectAll(); select(item); } slotShowMainPopupMenu(areaListView->listView->viewport()->mapToGlobal(p)); } void KImageMapEditor::updateStatusBar() { emit setStatusBarText(selectionStatusText+" "+cursorStatusText); } void KImageMapEditor::slotChangeStatusCoords(int x,int y) { // statusBar()->changeItem(QString(" Cursor : x: %1 ,y: %2 ").arg(x).arg(y),STATUS_CURSOR); cursorStatusText = i18n(" Cursor: x: %1, y: %2 ", x, y); updateStatusBar(); } void KImageMapEditor::slotUpdateSelectionCoords() { if (selected()->count()>0) { QRect r=selected()->rect(); // statusBar()->changeItem( selectionStatusText = i18n(" Selection: x: %1, y: %2, w: %3, h: %4 ", r.left(), r.top(), r.width(), r.height()); // ,STATUS_SELECTION); qApp->processEvents(); } else selectionStatusText = i18n(" Selection: - "); //statusBar()->changeItem(" Selection : - ",STATUS_SELECTION); updateStatusBar(); } void KImageMapEditor::slotUpdateSelectionCoords( const QRect & r ) { selectionStatusText = i18n(" Selection: x: %1, y: %2, w: %3, h: %4 ", r.left(), r.top(), r.width(), r.height()); updateStatusBar(); qApp->processEvents(); } void KImageMapEditor::drawToCenter(QPainter* p, const QString & str, int y, int width) { int xmid = width / 2; QFontMetrics fm = p->fontMetrics(); QRect strBounds = fm.boundingRect(str); p->drawText(xmid-(strBounds.width()/2),y,str); } QImage KImageMapEditor::getBackgroundImage() { // Lazy initialisation if ( _backgroundImage.isNull() ) { // QString filename = QString("dropimage_")+KGlobal::locale()->language()+".png"; // QString path = QString(); //KGlobal::dirs()->findResourceDir( "data", "kimagemapeditor/"+filename ) + "kimagemapeditor/"+filename; // qCDebug(KIMAGEMAPEDITOR_LOG) << "getBackgroundPic : loaded image : " << path; // if ( ! QFileInfo(path).exists() ) { int width = 400; int height = 400; int border = 20; int fontSize = 58; QPixmap pix(width,height); pix.fill(QColor(74,76,74)); QPainter p(&pix); // QFont font = QFontDatabase().font("Luxi Sans","Bold",fontSize); QFont font; font.setBold(true); font.setPixelSize(fontSize); p.setFont( font ); p.setCompositionMode(QPainter::CompositionMode_Source); p.setPen(QPen(QColor(112,114,112),1)); // The translated string must be divided into // parts with about the same size that fit to the image QString str = i18n("Drop an image or HTML file"); const QStringList strList = str.split(" "); // Get the string parts QString tmp; QStringList outputStrList; QFontMetrics fm = p.fontMetrics(); for ( QStringList::ConstIterator it = strList.begin(); it != strList.end(); ++it ) { QString tmp2 = tmp + *it; if (fm.boundingRect(tmp2).width() > width-border) { outputStrList.append(tmp); tmp = *it + ' '; } else tmp = tmp2 + ' '; } // Last one was forgotten so add it. outputStrList.append(tmp); // Try to adjust the text vertically centered int step = myround(float(height) / (outputStrList.size()+1)); int y = step; for ( QStringList::Iterator it = outputStrList.begin(); it != outputStrList.end(); ++it ) { drawToCenter(&p, *it, y, pix.width()); y += step; } p.end(); _backgroundImage = pix.toImage(); } return _backgroundImage; /* QFontDatabase fdb; QStringList families = fdb.families(); for ( QStringList::Iterator f = families.begin(); f != families.end(); ++f ) { QString family = *f; qDebug( family ); QStringList styles = fdb.styles( family ); for ( QStringList::Iterator s = styles.begin(); s != styles.end(); ++s ) { QString style = *s; QString dstyle = "\t" + style + " ("; QValueList smoothies = fdb.smoothSizes( family, style ); for ( QValueList::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) { dstyle += QString::number( *points ) + " "; } dstyle = dstyle.left( dstyle.length() - 1 ) + ")"; qDebug( dstyle ); } } path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "kimagemapeditor/" ) +filename; qCDebug(KIMAGEMAPEDITOR_LOG) << "getBackgroundPic : save new image to : " << path; pix.save(path,"PNG",100); } if ( ! QFileInfo(path).exists() ) { qCCritical(KIMAGEMAPEDITOR_LOG) << "Couldn't find needed " << filename << " file in " "the data directory of KImageMapEditor.\n" "Perhaps you have forgotten to do a make install !" << endl; exit(1); } */ } void KImageMapEditor::addArea(Area* area) { if (!area) return; // Perhaps we've got a selection of areas // so test it and add all areas of the selection // nested selections are possible but doesn't exist AreaSelection *selection=0L; if ( (selection = dynamic_cast ( area ) ) ) { AreaListIterator it = selection->getAreaListIterator(); while (it.hasNext()) { Area* a = it.next(); areas->prepend(a); a->setListViewItem(new QTreeWidgetItem( areaListView->listView, QStringList(a->attribute("href")))); a->listViewItem()->setIcon(1,QIcon(makeListViewPix(*a))); } } else { areas->prepend(area); area->setListViewItem(new QTreeWidgetItem( areaListView->listView, QStringList(area->attribute("href")))); area->listViewItem()->setIcon(1,QIcon(makeListViewPix(*area))); } setModified(true); } void KImageMapEditor::addAreaAndEdit(Area* s) { areas->prepend(s); s->setListViewItem(new QTreeWidgetItem( areaListView->listView, QStringList(s->attribute("href")))); s->listViewItem()->setIcon(1,QIcon(makeListViewPix(*s))); deselectAll(); select(s); if (!showTagEditor(selected())) { // If the user has pressed cancel // he undos the creation commandHistory()->undo(); } } void KImageMapEditor::deleteArea( Area * area ) { if (!area) return; // only for repaint reasons QRect redrawRect = area->selectionRect(); // Perhaps we've got a selection of areas // so test it and delete the whole selection // nested selections are possible but doesn't exist AreaSelection *selection=0L; if ( (selection = dynamic_cast ( area ) ) ) { AreaListIterator it = selection->getAreaListIterator(); while (it.hasNext()) { Area* a = it.next(); currentSelected->remove(a); areas->removeAll( a ); a->deleteListViewItem(); } } else { deselect( area ); areas->removeAll( area ); area->deleteListViewItem(); } drawZone->repaintRect(redrawRect); // Only to disable cut and copy actions if (areas->count()==0) deselectAll(); setModified(true); } void KImageMapEditor::deleteSelected() { AreaListIterator it = currentSelected->getAreaListIterator(); while (it.hasNext()) { Area *a = it.next(); currentSelected->remove( a ); areas->removeAll( a ); delete a->listViewItem(); } drawZone->repaintArea( *currentSelected ); // Only to disable cut and copy actions if (areas->count()==0) deselectAll(); setModified(true); } void KImageMapEditor::deleteAllAreas() { Area* a; foreach (a,*areas) { deselect( a ); areas->removeAll( a ); a->deleteListViewItem(); if (!areas->isEmpty()) a = areas->first(); // because the current is deleted } drawZone->repaint(); } void KImageMapEditor::updateAllAreas() { // qCDebug(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor::updateAllAreas"; Area* a; foreach(a,*areas) { a->listViewItem()->setIcon(1,QIcon(makeListViewPix(*a))); } drawZone->repaint(); } void KImageMapEditor::updateSelection() const { //FIXME: areaListView->listView->triggerUpdate(); } AreaSelection* KImageMapEditor::selected() const { return currentSelected; } void KImageMapEditor::select(Area* a) { if (!a) return; currentSelected->add(a); updateActionAccess(); slotUpdateSelectionCoords(); // drawZone->repaintArea( *a); } void KImageMapEditor::selectWithoutUpdate(Area* a) { if (!a) return; currentSelected->add(a); } void KImageMapEditor::slotSelectionChanged() { AreaListIterator it = areaList(); AreaList list = currentSelected->getAreaList(); while (it.hasNext()) { Area* a = it.next(); if ( a->listViewItem()->isSelected() != (list.contains(a)) ) { a->listViewItem()->isSelected() ? select( a ) : deselect( a ); drawZone->repaintArea( *a); } } } void KImageMapEditor::select( QTreeWidgetItem* item) { AreaListIterator it = areaList(); while (it.hasNext()) { Area* a = it.next(); if (a->listViewItem() == item ) { select( a ); drawZone->repaintArea( *a); } } } AreaListIterator KImageMapEditor::areaList() const { AreaListIterator it(*areas); return it; } void KImageMapEditor::slotAreaChanged(Area *area) { if (!area) return; setModified(true); AreaSelection *selection=0L; if ( (selection = dynamic_cast ( area ) ) ) { AreaListIterator it = selection->getAreaListIterator(); while (it.hasNext()) { Area* a = it.next(); if (a->listViewItem()) { a->listViewItem()->setText(0,a->attribute("href")); a->listViewItem()->setIcon(1,QIcon(makeListViewPix(*a))); } } } else if (area->listViewItem()) { area->listViewItem()->setText(0,area->attribute("href")); area->listViewItem()->setIcon(1,QIcon(makeListViewPix(*area))); } drawZone->repaintArea(*area); } void KImageMapEditor::deselect(Area* a) { if (a) { currentSelected->remove(a); // drawZone->repaintArea(*a); updateActionAccess(); slotUpdateSelectionCoords(); } } void KImageMapEditor::deselectWithoutUpdate(Area* a) { if (a) { currentSelected->remove(a); } } /** * Makes sure, that the actions cut, copy, delete and * show properties * can only be executed if sth. is selected. **/ void KImageMapEditor::updateActionAccess() { if (!isReadWrite()) return; if ( 0 < selected()->count()) { qCDebug(KIMAGEMAPEDITOR_LOG) << "actions enabled"; areaPropertiesAction->setEnabled(true); deleteAction->setEnabled(true); copyAction->setEnabled(true); cutAction->setEnabled(true); moveLeftAction->setEnabled(true); moveRightAction->setEnabled(true); moveUpAction->setEnabled(true); moveDownAction->setEnabled(true); toFrontAction->setEnabled(true); toBackAction->setEnabled(true); if ( (selected()->count() == 1) ) { if (selected()->type()==Area::Polygon) { increaseWidthAction->setEnabled(false); decreaseWidthAction->setEnabled(false); increaseHeightAction->setEnabled(false); decreaseHeightAction->setEnabled(false); addPointAction->setEnabled(true); removePointAction->setEnabled(true); } else { increaseWidthAction->setEnabled(true); decreaseWidthAction->setEnabled(true); increaseHeightAction->setEnabled(true); decreaseHeightAction->setEnabled(true); addPointAction->setEnabled(false); removePointAction->setEnabled(false); } } else { increaseWidthAction->setEnabled(false); decreaseWidthAction->setEnabled(false); increaseHeightAction->setEnabled(false); decreaseHeightAction->setEnabled(false); addPointAction->setEnabled(false); removePointAction->setEnabled(false); } } else { qCDebug(KIMAGEMAPEDITOR_LOG) << "Actions disabled"; areaPropertiesAction->setEnabled(false); deleteAction->setEnabled(false); copyAction->setEnabled(false); cutAction->setEnabled(false); moveLeftAction->setEnabled(false); moveRightAction->setEnabled(false); moveUpAction->setEnabled(false); moveDownAction->setEnabled(false); increaseWidthAction->setEnabled(false); decreaseWidthAction->setEnabled(false); increaseHeightAction->setEnabled(false); decreaseHeightAction->setEnabled(false); toFrontAction->setEnabled(false); toBackAction->setEnabled(false); addPointAction->setEnabled(false); removePointAction->setEnabled(false); } updateUpDownBtn(); } void KImageMapEditor::updateUpDownBtn() { if (!isReadWrite()) return; AreaList list = currentSelected->getAreaList(); if (list.isEmpty() || (areas->count() < 2)) { forwardOneAction->setEnabled(false); areaListView->upBtn->setEnabled(false); backOneAction->setEnabled(false); areaListView->downBtn->setEnabled(false); return; } // if the first Area is in the selection can't move up if (list.contains( areas->first() )) { forwardOneAction->setEnabled(false); areaListView->upBtn->setEnabled(false); } else { forwardOneAction->setEnabled(true); areaListView->upBtn->setEnabled(true); } drawZone->repaintArea(*currentSelected); // if the last Area is in the selection can't move down if (list.contains( areas->last() )) { backOneAction->setEnabled(false); areaListView->downBtn->setEnabled(false); } else { backOneAction->setEnabled(true); areaListView->downBtn->setEnabled(true); } } void KImageMapEditor::deselectAll() { QRect redrawRect= currentSelected->selectionRect(); currentSelected->reset(); drawZone->repaintRect(redrawRect); updateActionAccess(); } Area* KImageMapEditor::onArea(const QPoint & p) const { Area* s; foreach(s,*areas) { if (s->contains(p)) return s; } return 0L; } int KImageMapEditor::showTagEditor(Area *a) { if (!a) return 0; drawZone->repaintArea(*a); AreaDialog *dialog= new AreaDialog(this,a); connect (dialog, SIGNAL(areaChanged(Area*)), this, SLOT(slotAreaChanged(Area*))); int result = dialog->exec(); return result; } int KImageMapEditor::showTagEditor(QTreeWidgetItem *item) { if (!item) return 0; Area* a; foreach(a,*areas) { if (a->listViewItem()==item) { return showTagEditor(a); } } return 0; } int KImageMapEditor::showTagEditor() { return showTagEditor(selected()); } QString KImageMapEditor::getHTMLImageMap() const { QString retStr; retStr+="\n"; Area* a; foreach(a,*areas) { retStr+=" "+a->getHTMLCode()+'\n'; } if (defaultArea && defaultArea->finished()) retStr+=" "+defaultArea->getHTMLCode()+'\n'; retStr+=""; return retStr; } QPixmap KImageMapEditor::makeListViewPix(Area & a) { QPixmap pix=a.cutOut(drawZone->picture()); double shrinkFactor=1; // picture fits into max row height ? if (maxAreaPreviewHeight < pix.height()) shrinkFactor = ( (double) maxAreaPreviewHeight / pix.height() ); QPixmap pix2((int)(pix.width()*shrinkFactor), (int)(pix.height()*shrinkFactor)); // Give all pixels a defined color pix2.fill(Qt::white); QPainter p(&pix2); p.scale(shrinkFactor,shrinkFactor); p.drawPixmap(0,0,pix); return pix2; } void KImageMapEditor::setMapName(const QString & s) { mapsListView->changeMapName(_mapName, s); _mapName=s; currentMapElement->mapTag->name = s; } void KImageMapEditor::setPicture(const QUrl & url) { _imageUrl=url; if (QFileInfo(url.path()).exists()) { QImage img(url.path()); if (!img.isNull()) { setPicture(img); imageRemoveAction->setEnabled(true); imageUsemapAction->setEnabled(true); } else qCCritical(KIMAGEMAPEDITOR_LOG) << QString("The image %1 could not be opened.").arg(url.path()) << endl; } else qCCritical(KIMAGEMAPEDITOR_LOG) << QString("The image %1 does not exist.").arg(url.path()) << endl; } void KImageMapEditor::setPicture(const QImage & pix) { drawZone->setPicture(pix); updateAllAreas(); } void KImageMapEditor::slotDrawArrow() { _currentToolType=KImageMapEditor::Selection; } void KImageMapEditor::slotDrawCircle() { _currentToolType=KImageMapEditor::Circle; qCDebug(KIMAGEMAPEDITOR_LOG) << "slotDrawCircle"; } void KImageMapEditor::slotDrawRectangle() { _currentToolType=KImageMapEditor::Rectangle; qCDebug(KIMAGEMAPEDITOR_LOG) << "slotDrawRectangle"; } void KImageMapEditor::slotDrawPolygon() { _currentToolType=KImageMapEditor::Polygon; qCDebug(KIMAGEMAPEDITOR_LOG) << "slotDrawPolygon"; } void KImageMapEditor::slotDrawFreehand() { _currentToolType=KImageMapEditor::Freehand; } void KImageMapEditor::slotDrawAddPoint() { _currentToolType=KImageMapEditor::AddPoint; } void KImageMapEditor::slotDrawRemovePoint() { _currentToolType=KImageMapEditor::RemovePoint; } void KImageMapEditor::slotZoom() { int i=zoomAction->currentItem(); switch (i) { case 0 : drawZone->setZoom(0.25);break; case 1 : drawZone->setZoom(0.5);break; case 2 : drawZone->setZoom(1);break; case 3 : drawZone->setZoom(1.5);break; case 4 : drawZone->setZoom(2.0);break; case 5 : drawZone->setZoom(2.5);break; case 6 : drawZone->setZoom(3);break; case 7 : drawZone->setZoom(5);break; case 8 : drawZone->setZoom(7.5);break; case 9 : drawZone->setZoom(10);break; } if (i<10) zoomInAction->setEnabled(true); else zoomInAction->setEnabled(false); if (i>0) zoomOutAction->setEnabled(true); else zoomOutAction->setEnabled(false); } void KImageMapEditor::slotZoomIn() { if (zoomAction->currentItem()==(int)(zoomAction->items().count()-1)) return; zoomAction->setCurrentItem(zoomAction->currentItem()+1); slotZoom(); } void KImageMapEditor::slotZoomOut() { if (zoomAction->currentItem()==0) return; zoomAction->setCurrentItem(zoomAction->currentItem()-1); slotZoom(); } void KImageMapEditor::mapDefaultArea() { if (defaultArea) showTagEditor(defaultArea); else { defaultArea= new DefaultArea(); showTagEditor(defaultArea); } } void KImageMapEditor::mapEditName() { bool ok=false; QString input = QInputDialog::getText(widget(), i18n("Enter Map Name"), i18n("Enter the name of the map:"), QLineEdit::Normal, _mapName, &ok); if (ok && !input.isEmpty()) { if (input != _mapName) { if (mapsListView->nameAlreadyExists(input)) KMessageBox::sorry(this->widget(), i18n("The name %1 already exists.", input)); else { setMapName(input); } } } } void KImageMapEditor::mapShowHTML() { QDialog *dialog = new QDialog(widget()); dialog->setModal(true); dialog->setWindowTitle(i18n("HTML Code of Map")); QVBoxLayout *mainLayout = new QVBoxLayout(dialog); QTextEdit *edit = new QTextEdit; edit->setPlainText(getHtmlCode()); edit->setReadOnly(true); edit->setLineWrapMode(QTextEdit::NoWrap); mainLayout->addWidget(edit); // dialog->resize(dialog->calculateSize(edit->maxLineWidth(),edit->numLines()*)); // dialog->adjustSize(); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); mainLayout->addWidget(buttonBox); dialog->resize(600,400); dialog->exec(); delete dialog; } void KImageMapEditor::openFile(const QUrl & url) { if ( ! url.isEmpty()) { QMimeDatabase db; QMimeType openedFileType = db.mimeTypeForUrl(url); if (openedFileType.name().left(6) == "image/") { addImage(url); } else { openURL(url); } } } bool KImageMapEditor::openURL(const QUrl & url) { // If a local file does not exist // we start with an empty file, so // that we can return true here. // For non local files, we cannot check // the existence if (url.isLocalFile() && ! QFile::exists(url.path())) return true; return KParts::ReadWritePart::openUrl(url); } void KImageMapEditor::fileOpen() { QString fileName = QFileDialog::getOpenFileName(widget(), i18n("Choose File to Open"), QString(), i18n("Web File (*.png *.jpg *.jpeg *.gif *.htm *.html);;Images (*.png *.jpg *.jpeg *.gif *.bmp *.xbm *.xpm *.pnm *.mng);;" "HTML Files (*.htm *.html);;All Files (*)")); openFile(QUrl::fromUserInput( fileName )); } void KImageMapEditor::fileClose() { if (! closeUrl()) return; setPicture(getBackgroundImage()); recentFilesAction->setCurrentItem(-1); setModified(false); } void KImageMapEditor::fileSave() { // if we aren't read-write, return immediately if ( ! isReadWrite() ) return; if (url().isEmpty()) { fileSaveAs(); } else { saveFile(); setModified(false); } } void KImageMapEditor::fileSaveAs() { QUrl url = QFileDialog::getSaveFileUrl(widget(), QString(), QUrl(), i18n("HTML File (*.htm *.html);;Text File (*.txt);;All Files (*)" )); if (url.isEmpty() || !url.isValid()) { return; } QFileInfo fileInfo(url.path()); saveAs(url); recentFilesAction->addUrl(url); } bool KImageMapEditor::openFile() { QUrl u = url(); QFileInfo fileInfo(u.path()); if ( !fileInfo.exists() ) { KMessageBox::information(widget(), i18n("The file %1 does not exist.", fileInfo.fileName()), i18n("File Does Not Exist")); return false; } openHTMLFile(u); drawZone->repaint(); recentFilesAction->addUrl(u); setModified(false); backupFileCreated = false; return true; } /** * This method supposes that the given QTextStream s has just read * the < of a tag. It now reads all attributes of the tag until a > * The tagname itself is also read and stored as a tagname * attribute. After parsing the whole tag it returns a QDict * with all attributes and their values. It stores the whole read text in the * parameter readText. */ QHash KImageMapEditor::getTagAttributes(QTextStream & s, QString & readText) { QHash dict; // the "<" is already read QChar w; QString attr,value; readText.clear(); // get the tagname while (!s.atEnd() && w!=' ') { s >> w; readText.append(w); if (w.isSpace() || w=='>') { dict.insert("tagname",value); break; } value+=w; } // do we have a comment ? // read the comment and return if (value.right(3)=="-->") return dict; if (value.startsWith("!--")) { while (!s.atEnd()) { s >> w; readText.append(w); if (w=='-') { s >> w; readText.append(w); if (w=='-') { s >> w; readText.append(w); if (w=='>') return dict; } } } } bool attrRead=true; // currently reading an attribute ? bool equalSign=false; // an equalsign was read? bool valueRead=false; // currently reading a value ? QChar quotation='\0'; // currently reading a value with quotation marks ? bool php=false; // currently reading a php script attr.clear(); value.clear(); //get the other attributes while (!s.atEnd() && w!='>') { s >> w; readText.append(w); // End of PHP Script ? if (php && (w=='?') ) { s >> w; readText.append(w); if (valueRead) value+=w; if (w=='>') { php = false; s >> w; readText.append(w); } } // Wrong syntax or PHP-Script ! if (!php && (w=='<')) { if (valueRead) value+=w; s >> w; readText.append(w); if (valueRead) value+=w; if (w=='?') { php = true; } } else // finished ? if (w=='>') { if (valueRead) { dict.insert(attr,value); } return dict; } else // currently reading an attribute ? if (attrRead) { // if there is a whitespace the attributename has finished // possibly there isn't any value e.g. noshade if (w.isSpace()) attrRead=false; else // an equal sign signals that the value follows if (w=='=') { attrRead=false; equalSign=true; } else attr+=w; } else // an equal sign was read ? delete every whitespace if (equalSign) { if (!w.isSpace()) { equalSign=false; valueRead=true; if (w=='"' || w=='\'') quotation=w; } } else // currently reading the value if (valueRead) { // if php, read without regarding anything if (php) value+=w; // if value within quotation marks is read // only stop when another quotationmark is found else if (quotation != '\0') { if (quotation!=w) { value+=w; } else { quotation='\0'; valueRead=false; dict.insert(attr,value); attr.clear(); value.clear(); } } else // a whitespace indicates that the value has finished if (w.isSpace()) { valueRead=false; dict.insert(attr,value); attr.clear(); value.clear(); } } else { if (!w.isSpace()) { attrRead=true; attr+=w; } } } return dict; } bool KImageMapEditor::openHTMLFile(const QUrl & url) { QFile f(url.path()); if ( !f.exists () ) return false; f.open(QIODevice::ReadOnly); QTextStream s(&f); QString str; QChar w; QHash *attr=0L; QList images; MapTag *map=0L; QList maps; _htmlContent.clear(); currentMapElement = 0L; QString temp; QString origcode; bool readMap=false; while (!s.atEnd()) { s >> w; if (w=='<') { if (!readMap && !origcode.isEmpty()) { _htmlContent.append( new HtmlElement(origcode)); origcode.clear(); } origcode.append("<"); attr=new QHash(getTagAttributes(s,temp)); origcode.append(temp); if (attr->contains("tagname")) { QString tagName = attr->value("tagname").toLower(); if (tagName =="img") { HtmlImgElement *el = new HtmlImgElement(origcode); el->imgTag = static_cast(attr); images.append(el->imgTag); _htmlContent.append(el); origcode.clear(); } else if (tagName == "map") { map = new MapTag(); map->name = attr->value("name"); qCDebug(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor::openHTMLFile: found map with name:" << map->name; readMap=true; } else if (tagName=="/map") { readMap=false; maps.append(map); HtmlMapElement *el = new HtmlMapElement(origcode); el->mapTag = map; _htmlContent.append(el); origcode.clear(); } else if (readMap) { if (tagName=="area") { map->prepend(*attr); } } else { _htmlContent.append(new HtmlElement(origcode)); origcode.clear(); } } } // w != "<" else { origcode.append(w); } } if (!origcode.isEmpty()) { _htmlContent.append(new HtmlElement(origcode)); } f.close(); QUrl imageUrl; map = 0L; // If we have more than on map or more than one image // Let the user choose, otherwise take the only ones if (maps.count() > 1) { map = maps.first(); } if (images.count() > 1) { ImageTag* imgTag = images.first(); if (imgTag) { if (imgTag->contains("src")) { if (url.path().isEmpty() | !url.path().endsWith('/')) { imageUrl = QUrl(url.path() + '/').resolved(QUrl(imgTag->value("src"))); } else { imageUrl = url.resolved(QUrl(imgTag->value("src"))); } } } } // If there is more than one map and more than one image // use the map that has an image with an according usemap tag if (maps.count() > 1 && images.count() > 1) { bool found = false; MapTag *mapTag; foreach(mapTag, maps) { ImageTag *imageTag; foreach(imageTag, images) { if (imageTag->contains("usemap")) { QString usemap = imageTag->value("usemap"); // Remove the # QString usemapName = usemap.right(usemap.length()-1); if (usemapName == mapTag->name) { if (imageTag->contains("src")) { if (url.path().isEmpty() | !url.path().endsWith('/')) { imageUrl = QUrl(url.path() + '/').resolved(QUrl(imageTag->value("src"))); } else { imageUrl = url.resolved(QUrl(imageTag->value("src"))); } found = true; } } } if (found) break; } if (found) break; } if (found) { map = mapTag; } } // If there are more than one map or there wasn't // found a fitting image and there is something to choose // let the user choose /* if (maps.count() >1 || (imageUrl.isEmpty() && images.count() > 1)) { ImageMapChooseDialog dialog(widget(),maps,images,url); qCDebug(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor::openHTMLFile: before dialog->exec()"; dialog.exec(); qCDebug(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor::openHTMLFile: after dialog->exec()"; map = dialog.currentMap; imageUrl = dialog.pixUrl; }*/ imagesListView->clear(); imagesListView->setBaseUrl(url); imagesListView->addImages(images); mapsListView->clear(); mapsListView->addMaps(maps); setMapActionsEnabled(false); if (map) { mapsListView->selectMap(map->name); } else { #ifdef WITH_TABWIDGET if (tabWidget) tabWidget->showPage(mapsListView); #endif } if (!imageUrl.isEmpty()) { setPicture(imageUrl); } else { setPicture(getBackgroundImage()); #ifdef WITH_TABWIDGET if (tabWidget) tabWidget->showPage(imagesListView); #endif } emit setWindowCaption(url.fileName()); setModified(false); return true; } /** * Finds the first html element which contains the given text. * Returns the first matching element. * Returns 0L if no element was found. */ HtmlElement* KImageMapEditor::findHtmlElement(const QString & containingText) { HtmlElement *el; foreach (el,_htmlContent) { if (el->htmlCode.contains(containingText,Qt::CaseInsensitive)) { return el; } } return 0L; } /** * Finds the first html element which contains the given ImageTag. * Returns the first matching element. * Returns 0L if no element was found. */ HtmlImgElement* KImageMapEditor::findHtmlImgElement(ImageTag* tag) { HtmlElement* el; foreach(el,_htmlContent) { HtmlImgElement* imgEl = dynamic_cast(el); if (imgEl && imgEl->imgTag == tag) return imgEl; } return 0L; } void KImageMapEditor::addMap(const QString & name = QString()) { HtmlMapElement* el = new HtmlMapElement("\n"); MapTag* map = new MapTag(); map->name = name; el->mapTag = map; // Try to find the body tag HtmlElement* bodyTag = findHtmlElement("addMap(name); mapsListView->selectMap(name); } /** * Finds the HtmlMapElement in the HtmlContent, that corresponds * to the given map name.
* Returns 0L if there exists no map with the given name */ HtmlMapElement* KImageMapEditor::findHtmlMapElement(const QString & mapName) { foreach(HtmlElement * el,_htmlContent) { if (dynamic_cast(el)) { HtmlMapElement *tagEl = static_cast(el); if (tagEl->mapTag->name == mapName) { return tagEl; } } } qCWarning(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor::findHtmlMapElement: couldn't find map '" << mapName << "'"; return 0L; } /** * Calls setMap with the HtmlMapElement with the given map name */ void KImageMapEditor::setMap(const QString & mapName) { HtmlMapElement* el = findHtmlMapElement(mapName); if (!el) { qCWarning(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor::setMap : Couldn't set map '" << mapName << "', because it wasn't found !"; return; } setMap(el); } void KImageMapEditor::setMap(MapTag* map) { HtmlElement * el; foreach(el,_htmlContent) { HtmlMapElement *tagEl = dynamic_cast(el); if (tagEl) { if (tagEl->mapTag == map) { setMap(tagEl); break; } } } } void KImageMapEditor::saveAreasToMapTag(MapTag* map) { map->clear(); Area* a; foreach(a,*areas) { QString shapeStr; switch (a->type()) { case Area::Rectangle : shapeStr = "rect";break; case Area::Circle : shapeStr = "circle";break; case Area::Polygon : shapeStr = "poly";break; default : continue; } QHash dict; dict.insert("shape",shapeStr); AttributeIterator it = a->attributeIterator(); while (it.hasNext()) { it.next(); dict.insert(it.key(),it.value()); } dict.insert("coords",a->coordsToString()); map->append(dict); } if (defaultArea && defaultArea->finished()) { QHash dict; dict.insert("shape","default"); AttributeIterator it = defaultArea->attributeIterator(); while (it.hasNext()) { it.next(); dict.insert(it.key(),it.value()); } map->append(dict); } } static void setAttribute(Area* a, const AreaTag & tag, const QString & s) { if (tag.contains(s)) a->setAttribute(s,tag.value(s)); } void KImageMapEditor::setMap(HtmlMapElement* mapElement) { if (currentMapElement) { currentMapElement->mapTag->modified=true; currentMapElement->htmlCode = getHTMLImageMap(); saveAreasToMapTag(currentMapElement->mapTag); } currentMapElement = mapElement; MapTag* map = currentMapElement->mapTag; // Remove old areas only if a new map is loaded deleteAllAreas(); delete defaultArea; defaultArea = 0L; // qCDebug(KIMAGEMAPEDITOR_LOG) << "KImageMapEditor::setMap : Setting new map : " << map->name; _mapName = map->name; AreaTag tag; QLinkedListIterator it(*map); while (it.hasNext()) { tag = it.next(); QString shape="rect"; if (tag.contains("shape")) shape=tag.value("shape"); Area::ShapeType type=Area::Rectangle; if (shape=="circle") type=Area::Circle; else if (shape=="poly") type=Area::Polygon; else if (shape=="default") type=Area::Default; Area* a=AreaCreator::create(type); setAttribute(a,tag,"href"); setAttribute(a,tag,"alt"); setAttribute(a,tag,"target"); setAttribute(a,tag,"title"); setAttribute(a,tag,"onclick"); setAttribute(a,tag,"ondblclick"); setAttribute(a,tag,"onmousedown"); setAttribute(a,tag,"onmouseup"); setAttribute(a,tag,"onmouseover"); setAttribute(a,tag,"onmousemove"); setAttribute(a,tag,"onmouseout"); if (type==Area::Default) { defaultArea=a; defaultArea->setFinished(true); continue; } if (tag.contains("coords")) a->setCoords(tag.value("coords")); a->setMoving(false); addArea(a); } updateAllAreas(); setMapActionsEnabled(true); } /** * Sets whether actions that depend on an selected map * are enabled */ void KImageMapEditor::setMapActionsEnabled(bool b) { mapDeleteAction->setEnabled(b); mapDefaultAreaAction->setEnabled(b); mapNameAction->setEnabled(b); arrowAction->setChecked(true); slotDrawArrow(); arrowAction->setEnabled(b); circleAction->setEnabled(b); rectangleAction->setEnabled(b); polygonAction->setEnabled(b); freehandAction->setEnabled(b); addPointAction->setEnabled(b); removePointAction->setEnabled(b); } QString KImageMapEditor::getHtmlCode() { if (currentMapElement) { currentMapElement->htmlCode = getHTMLImageMap(); } QString result; HtmlElement *el; foreach(el,_htmlContent) { result += el->htmlCode; } return result; } /** create a relative short url based in baseURL taken from qextfileinfo.cpp: From WebMaker - KDE HTML Editor Copyright (C) 1998, 1999 Alexei Dets Rewritten for Quanta Plus: (C) 2002 Andras Mantia This program 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 2 of the License, or (at your option) any later version. */ static QUrl toRelative(const QUrl& urlToConvert,const QUrl& baseURL) { QUrl resultURL = urlToConvert; if (urlToConvert.scheme() == baseURL.scheme()) { QString path = urlToConvert.path(); QString basePath = baseURL.path().endsWith('/') ? baseURL.path() : baseURL.path() + '/'; if (path.startsWith("/") && basePath != "/") { path.remove(0, 1); basePath.remove(0, 1); if ( basePath.right(1) != "/" ) basePath.append("/"); int pos=0; int pos1=0; for (;;) { pos=path.indexOf("/"); pos1=basePath.indexOf("/"); if ( pos<0 || pos1<0 ) break; if ( path.left(pos+1 ) == basePath.left(pos1+1) ) { path.remove(0, pos+1); basePath.remove(0, pos1+1); } else break; }; if ( basePath == "/" ) basePath=""; int level = basePath.count("/"); for (int i=0; iThe file %1 could not be saved, because you do not have the required write permissions.", url.path())); return; } if (!backupFileCreated) { QString backupFile = url.path()+'~'; KIO::file_copy(url, QUrl::fromUserInput(backupFile ), -1, KIO::Overwrite | KIO::HideProgressInfo); backupFileCreated = true; } setModified(false); if (mapName().isEmpty()) { mapEditName(); } QFile file(url.path()); file.open(QIODevice::WriteOnly); QTextStream t(&file); if (_htmlContent.isEmpty()) { t << "\n" << "\n" << " \n" << "\n" << "\n" << " " << getHTMLImageMap() << "\n" << " picture().width() << "\"" << " height=\"" << drawZone->picture().height() << "\">\n" << "\n" << ""; } else { t << getHtmlCode(); } file.close(); } void KImageMapEditor::slotCut() { if ( 0 == currentSelected->count() ) return; delete copyArea; copyArea= static_cast< AreaSelection* > (currentSelected->clone()); pasteAction->setEnabled(true); QUndoCommand *command= new CutCommand(this,*currentSelected); commandHistory()->push(command); } void KImageMapEditor::slotDelete() { if ( 0 == currentSelected->count() ) return; QUndoCommand *command= new DeleteCommand(this,*currentSelected); commandHistory()->push(command); } void KImageMapEditor::slotCopy() { delete copyArea; copyArea = static_cast< AreaSelection* > (currentSelected->clone()); pasteAction->setEnabled(true); } void KImageMapEditor::slotPaste() { if (!copyArea) return; copyArea->moveBy(5,5); if (copyArea->rect().x()>= drawZone->getImageRect().width() || copyArea->rect().y()>= drawZone->getImageRect().height()) copyArea->moveTo(0,0); if (copyArea->rect().width()>drawZone->getImageRect().width() || copyArea->rect().height()>drawZone->getImageRect().height()) return; AreaSelection *a=static_cast< AreaSelection* > (copyArea->clone()); commandHistory()->push(new PasteCommand(this,*a)); delete a; // addAreaAndEdit(a); } void KImageMapEditor::slotBackOne() { if (currentSelected->isEmpty()) return; AreaList list = currentSelected->getAreaList(); Area *a = 0L; // move every selected Area one step lower for (int i=areas->count()-2; i > -1; i--) { if (list.contains( areas->at(i) )) { uint j = (uint)i+1; a = areas->at(i); areas->removeAll(a); areas->insert(j,a); QTreeWidgetItem* root = areaListView->listView->invisibleRootItem(); root->insertChild(j,root->takeChild(i)); } } // to update the up and down buttons updateUpDownBtn(); } void KImageMapEditor::slotForwardOne() { if (currentSelected->isEmpty()) return; AreaList list = currentSelected->getAreaList(); Area *a = 0L; // move every selected Area one step higher for (int i=1; i < (int)areas->count(); i++) { if (list.contains( areas->at(i) )) { uint j = (uint) i-1; a = areas->at(i); areas->removeAll(a); areas->insert(j,a); QTreeWidgetItem* root = areaListView->listView->invisibleRootItem(); root->insertChild(j,root->takeChild(i)); } } // to update the up and down buttons updateUpDownBtn(); } void KImageMapEditor::slotToBack() { if (currentSelected->isEmpty()) return; while (backOneAction->isEnabled()) slotBackOne(); } void KImageMapEditor::slotToFront() { if (currentSelected->isEmpty()) return; while (forwardOneAction->isEnabled()) slotForwardOne(); } void KImageMapEditor::slotMoveUp() { QRect r=selected()->rect(); selected()->setMoving(true); selected()->moveBy(0,-1); commandHistory()->push( new MoveCommand( this, selected(), r.topLeft() )); selected()->setMoving(false); slotAreaChanged(selected()); slotUpdateSelectionCoords(); } void KImageMapEditor::slotMoveDown() { QRect r=selected()->rect(); selected()->setMoving(true); selected()->moveBy(0,1); commandHistory()->push( new MoveCommand( this, selected(), r.topLeft() )); selected()->setMoving(false); slotAreaChanged(selected()); slotUpdateSelectionCoords(); } void KImageMapEditor::slotMoveLeft() { qCDebug(KIMAGEMAPEDITOR_LOG) << "slotMoveLeft"; QRect r=selected()->rect(); selected()->setMoving(true); selected()->moveBy(-1,0); commandHistory()->push( new MoveCommand( this, selected(), r.topLeft() )); selected()->setMoving(false); slotAreaChanged(selected()); slotUpdateSelectionCoords(); } void KImageMapEditor::slotMoveRight() { QRect r=selected()->rect(); selected()->setMoving(true); selected()->moveBy(1,0); commandHistory()->push( new MoveCommand( this, selected(), r.topLeft() )); selected()->setMoving(false); slotAreaChanged(selected()); slotUpdateSelectionCoords(); } void KImageMapEditor::slotCancelDrawing() { drawZone->cancelDrawing(); } void KImageMapEditor::slotIncreaseHeight() { Area *oldArea=selected()->clone(); QRect r = selected()->rect(); r.setHeight( r.height()+1 ); r.translate(0,-1); selected()->setRect(r); commandHistory()->push( new ResizeCommand( this, selected(), oldArea )); slotAreaChanged(selected()); slotUpdateSelectionCoords(); } void KImageMapEditor::slotDecreaseHeight() { Area *oldArea=selected()->clone(); QRect r = selected()->rect(); r.setHeight( r.height()-1 ); r.translate(0,1); selected()->setRect(r); commandHistory()->push( new ResizeCommand( this, selected(), oldArea )); slotAreaChanged(selected()); slotUpdateSelectionCoords(); } void KImageMapEditor::slotIncreaseWidth() { Area *oldArea=selected()->clone(); QRect r = selected()->rect(); r.setWidth( r.width()+1 ); selected()->setRect(r); commandHistory()->push( new ResizeCommand( this, selected(), oldArea )); slotAreaChanged(selected()); slotUpdateSelectionCoords(); } void KImageMapEditor::slotDecreaseWidth() { Area *oldArea=selected()->clone(); QRect r = selected()->rect(); r.setWidth( r.width()-1 ); selected()->setRect(r); commandHistory()->push( new ResizeCommand( this, selected(), oldArea )); slotAreaChanged(selected()); slotUpdateSelectionCoords(); } void KImageMapEditor::slotHighlightAreas(bool b) { Area::highlightArea = b; updateAllAreas(); drawZone->repaint(); } void KImageMapEditor::slotShowAltTag(bool b) { Area::showAlt = b; drawZone->repaint(); } void KImageMapEditor::mapNew() { QString mapName = mapsListView->getUnusedMapName(); addMap(mapName); mapEditName(); } void KImageMapEditor::mapDelete() { if (mapsListView->count() == 0) return; QString selectedMap = mapsListView->selectedMap(); int result = KMessageBox::warningContinueCancel(widget(), i18n("Are you sure you want to delete the map %1?" "
There is no way to undo this.
", selectedMap), i18n("Delete Map?"),KGuiItem(i18n("&Delete"),"edit-delete")); if (result == KMessageBox::Cancel) return; mapsListView->removeMap(selectedMap); HtmlMapElement* mapEl = findHtmlMapElement(selectedMap); _htmlContent.removeAll(mapEl); if (mapsListView->count() == 0) { currentMapElement = 0L; deleteAllAreas(); setMapActionsEnabled(false); } else { // The old one was deleted, so the new one got selected setMap(mapsListView->selectedMap()); } } void KImageMapEditor::mapPreview() { HTMLPreviewDialog dialog(widget(), getHtmlCode()); dialog.exec(); } void KImageMapEditor::deleteAllMaps() { deleteAllAreas(); mapsListView->clear(); if (isReadWrite()) { mapDeleteAction->setEnabled(false); mapDefaultAreaAction->setEnabled(false); mapNameAction->setEnabled(false); } } /** * Doesn't call the closeUrl method, because * we need the URL for the session management */ bool KImageMapEditor::queryClose() { if ( ! isModified() ) return true; switch ( KMessageBox::warningYesNoCancel( widget(), i18n("The file %1 has been modified.
Do you want to save it?
", url().fileName()), QString(), KStandardGuiItem::save(), KStandardGuiItem::discard()) ) { case KMessageBox::Yes : saveFile(); return true; case KMessageBox::No : return true; default: return false; } } bool KImageMapEditor::closeUrl() { bool result = KParts::ReadWritePart::closeUrl(); if (!result) return false; _htmlContent.clear(); deleteAllMaps(); imagesListView->clear(); delete copyArea; copyArea=0L; delete defaultArea; defaultArea=0L; currentMapElement = 0L; init(); emit setWindowCaption(""); return true; } void KImageMapEditor::addImage(const QUrl & imgUrl) { if (imgUrl.isEmpty()) return; QString relativePath ( toRelative(imgUrl, QUrl( url().adjusted(QUrl::RemoveFilename).path() )).path() ); QString imgHtml = QString(""); ImageTag* imgTag = new ImageTag(); imgTag->insert("tagname","img"); imgTag->insert("src", relativePath); HtmlImgElement* imgEl = new HtmlImgElement(imgHtml); imgEl->imgTag = imgTag; HtmlElement* bodyEl = findHtmlElement("addImage(imgTag); imagesListView->selectImage(imgTag); setImageActionsEnabled(true); setModified(true); } /** * Sets whether the image actions that depend on an * selected image are enabled */ void KImageMapEditor::setImageActionsEnabled(bool b) { imageRemoveAction->setEnabled(b); imageUsemapAction->setEnabled(b); } void KImageMapEditor::imageAdd() { QUrl imgUrl = QFileDialog::getOpenFileUrl(widget(), i18n("Select image"), QUrl(), i18n("Images (*.png *.jpg *.jpeg *.gif *.bmp *.xbm *.xpm *.pnm *.mng);;All Files (*)")); addImage(imgUrl); } void KImageMapEditor::imageRemove() { ImageTag* imgTag = imagesListView->selectedImage(); HtmlImgElement* imgEl = findHtmlImgElement(imgTag); imagesListView->removeImage(imgTag); _htmlContent.removeAt(_htmlContent.indexOf(imgEl)); if (imagesListView->topLevelItemCount() == 0) { setPicture(getBackgroundImage()); setImageActionsEnabled(false); } else { ImageTag* selected = imagesListView->selectedImage(); if (selected) { if (selected->contains("src")) { setPicture(QUrl(selected->value("src"))); } } } setModified(true); } void KImageMapEditor::imageUsemap() { bool ok=false; ImageTag* imageTag = imagesListView->selectedImage(); if ( ! imageTag) return; QString usemap; if (imageTag->contains("usemap")) usemap = imageTag->value("usemap"); QStringList maps = mapsListView->getMaps(); int index = maps.indexOf(usemap); if (index == -1) { maps.prepend(""); index = 0; } QString input = QInputDialog::getItem(widget(), i18n("Enter Usemap"), i18n("Enter the usemap value:"), maps, index, true, &ok); if (ok) { imageTag->insert("usemap", input); imagesListView->updateImage(imageTag); setModified(true); // Update the htmlCode of the HtmlElement HtmlImgElement* imgEl = findHtmlImgElement(imageTag); imgEl->htmlCode = "<"; QString tagName = imgEl->imgTag->value("tagname"); imgEl->htmlCode += QString(tagName); QHashIterator it( *imgEl->imgTag ); while (it.hasNext()) { it.next(); if (it.key() != "tagname") { imgEl->htmlCode += " " + it.key() + "=\""; if (it.key() == "usemap") imgEl->htmlCode += '#'; imgEl->htmlCode += it.value(); imgEl->htmlCode += '"'; } } imgEl->htmlCode += '>'; } } #include "kimagemapeditor.moc" diff --git a/kimedialogs.cpp b/kimedialogs.cpp index 888e451..20fecb2 100644 --- a/kimedialogs.cpp +++ b/kimedialogs.cpp @@ -1,635 +1,635 @@ /*************************************************************************** kimedialogs.cpp - description ------------------- begin : Tue Apr 17 2001 copyright : (C) 2001 by Jan Schäfer email : j_schaef@informatik.uni-kl.de ***************************************************************************/ /*************************************************************************** * * * This program 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 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // LOCAL #include "kimedialogs.h" // Qt #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // KDE Frameworks #include "kimagemapeditor_debug.h" #include #include #include #include #include #include CoordsEdit::CoordsEdit(QWidget *parent, Area* a) : QWidget(parent) { area=a; } void CoordsEdit::applyChanges() { return; } void CoordsEdit::slotTriggerUpdate() { applyChanges(); emit update(); } CoordsEdit::~CoordsEdit() { } RectCoordsEdit::RectCoordsEdit(QWidget *parent, Area* a) : CoordsEdit(parent,a) { QFormLayout *layout= new QFormLayout(this); topXSpin = new QSpinBox(this); topXSpin->setMaximum(INT_MAX); topXSpin->setMinimum(0); topXSpin->setValue(a->rect().left()); connect( topXSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate())); layout->addRow(i18n("Top &X:"), topXSpin); topYSpin = new QSpinBox(this); topYSpin->setMaximum(INT_MAX); topYSpin->setMinimum(0); topYSpin->setValue(a->rect().top()); connect( topYSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate())); layout->addRow(i18n("Top &Y:"), topYSpin); widthSpin = new QSpinBox(this); widthSpin->setMaximum(INT_MAX); widthSpin->setMinimum(0); widthSpin->setValue(a->rect().width()); connect( widthSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate())); layout->addRow(i18n("&Width:"), widthSpin); heightSpin = new QSpinBox(this); heightSpin->setMaximum(INT_MAX); heightSpin->setMinimum(0); heightSpin->setValue(a->rect().height()); connect( heightSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate())); layout->addRow(i18n("Hei&ght:"), heightSpin); } void RectCoordsEdit::applyChanges() { QRect r; r.setLeft(topXSpin->text().toInt()); r.setTop(topYSpin->text().toInt()); r.setWidth(widthSpin->text().toInt()); r.setHeight(heightSpin->text().toInt()); area->setRect(r); } CircleCoordsEdit::CircleCoordsEdit(QWidget *parent, Area* a) : CoordsEdit(parent,a) { QFormLayout *layout = new QFormLayout(this); centerXSpin = new QSpinBox(this); centerXSpin->setMaximum(INT_MAX); centerXSpin->setMinimum(0); centerXSpin->setValue(a->rect().center().x()); connect( centerXSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate())); layout->addRow(i18n("Center &X:"), centerXSpin); centerYSpin = new QSpinBox(this); centerYSpin->setMaximum(INT_MAX); centerYSpin->setMinimum(0); centerYSpin->setValue(a->rect().center().y()); connect( centerYSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate())); layout->addRow(i18n("Center &Y:"), centerYSpin); radiusSpin = new QSpinBox(this); radiusSpin->setMaximum(INT_MAX); radiusSpin->setMinimum(0); radiusSpin->setValue(a->rect().width()/2); connect( radiusSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate())); layout->addRow(i18n("&Radius:"), radiusSpin); } void CircleCoordsEdit::applyChanges() { QRect r; r.setWidth(radiusSpin->text().toInt()*2); r.setHeight(radiusSpin->text().toInt()*2); r.moveCenter(QPoint(centerXSpin->text().toInt(), centerYSpin->text().toInt())); area->setRect(r); } PolyCoordsEdit::PolyCoordsEdit(QWidget *parent, Area* a) : CoordsEdit(parent,a) { if (!a) return; QVBoxLayout *layout = new QVBoxLayout(this); coordsTable = new QTableWidget(0, 2); coordsTable->verticalHeader()->hide(); coordsTable->setSelectionMode( QTableWidget::SingleSelection ); connect( coordsTable, SIGNAL(currentChanged(int,int)), this, SLOT(slotHighlightPoint(int))); updatePoints(); // coordsTable->setMinimumHeight(50); // coordsTable->setMaximumHeight(400); // coordsTable->resizeContents(100,100); coordsTable->resize(coordsTable->width(), 100); layout->addWidget(coordsTable); layout->setStretchFactor(coordsTable, -1); QHBoxLayout *hbox = new QHBoxLayout; QPushButton *addBtn = new QPushButton(i18n("Add")); hbox->addWidget(addBtn); connect( addBtn, SIGNAL(pressed()), this, SLOT(slotAddPoint())); QPushButton *removeBtn = new QPushButton(i18n("Remove")); hbox->addWidget(removeBtn); connect( removeBtn, SIGNAL(pressed()), this, SLOT(slotRemovePoint())); layout->addLayout(hbox); slotHighlightPoint(1); } PolyCoordsEdit::~PolyCoordsEdit() { } void PolyCoordsEdit::slotHighlightPoint(int row) { if (!area) return; area->highlightSelectionPoint(row); emit update(); } void PolyCoordsEdit::updatePoints() { coordsTable->clear(); int count=area->coords().size(); coordsTable->setHorizontalHeaderLabels(QStringList() << "X" << "Y"); coordsTable->setRowCount(count); for (int i=0;isetItem(i,0, new QTableWidgetItem(QString::number(area->coords().point(i).x()) )); coordsTable->setItem(i,1, new QTableWidgetItem(QString::number(area->coords().point(i).y()) )); } emit update(); } void PolyCoordsEdit::slotAddPoint() { int newPos= coordsTable->currentRow(); if (newPos < 0 || newPos >= area->coords().size()) newPos = area->coords().size(); QPoint currentPoint=area->coords().point(newPos); area->insertCoord(newPos,currentPoint); updatePoints(); } void PolyCoordsEdit::slotRemovePoint() { int currentPos= coordsTable->currentRow(); if (currentPos < 0 || currentPos >= area->coords().size()) return; area->removeCoord(currentPos); updatePoints(); } void PolyCoordsEdit::applyChanges() { int count=coordsTable->rowCount(); for (int i=0;iitem(i,0)->text().toInt(), coordsTable->item(i,1)->text().toInt()); area->moveCoord(i,newPoint); } } SelectionCoordsEdit::SelectionCoordsEdit(QWidget *parent, Area* a) : CoordsEdit(parent,a) { QFormLayout *layout = new QFormLayout(this); topXSpin = new QSpinBox(this); topXSpin->setMaximum(INT_MAX); topXSpin->setMinimum(0); topXSpin->setValue(a->rect().left()); connect( topXSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate())); layout->addRow(i18n("Top &X"), topXSpin); topYSpin = new QSpinBox(this); topYSpin->setMaximum(INT_MAX); topYSpin->setMinimum(0); topYSpin->setValue(a->rect().top()); connect( topYSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate())); layout->addRow(i18n("Top &Y"), topYSpin); } void SelectionCoordsEdit::applyChanges() { area->moveTo(topXSpin->text().toInt(), topYSpin->text().toInt()); } QLineEdit* AreaDialog::createLineEdit(QFormLayout *layout, const QString &value, const QString &name) { QLineEdit *edit = new QLineEdit(value); layout->addRow(name, edit); return edit; } QWidget* AreaDialog::createGeneralPage() { QFrame *page = new QFrame(this); QFormLayout *layout = new QFormLayout(page); // A separate widget, not just a layout, is needed so that // the accelerator for the row is working QWidget *hbox = new QWidget; QHBoxLayout *hboxLayout = new QHBoxLayout(hbox); hboxLayout->setMargin(0); hrefEdit = new QLineEdit(area->attribute("href")); hboxLayout->addWidget(hrefEdit); QPushButton *btn = new QPushButton; btn->setIcon(SmallIcon("document-open")); connect( btn, SIGNAL(pressed()), this, SLOT(slotChooseHref())); hboxLayout->addWidget(btn); QLabel *lblHREF = new QLabel(i18n("&HREF:")); lblHREF->setBuddy(hrefEdit); layout->addRow(lblHREF, hbox); altEdit = createLineEdit(layout, area->attribute("alt"), i18n("Alt. &Text:")); targetEdit = createLineEdit(layout, area->attribute("target"), i18n("Tar&get:")); titleEdit = createLineEdit(layout, area->attribute("title"), i18n("Tit&le:")); if (area->type() == Area::Default) { defaultAreaChk = new QCheckBox(i18n("On")); if (area->finished()) { defaultAreaChk->setChecked(true); } layout->addRow(i18n("Enable default map"), defaultAreaChk); } return page; } QWidget* AreaDialog::createCoordsPage() { QFrame* page = new QFrame(this); QVBoxLayout *layout = new QVBoxLayout(page); layout->setMargin(5); coordsEdit = createCoordsEdit(page, area); layout->addWidget(coordsEdit); connect( coordsEdit, SIGNAL(update()), this, SLOT(slotUpdateArea())); return page; } QWidget* AreaDialog::createJavascriptPage() { QFrame *page = new QFrame(this); QFormLayout *layout = new QFormLayout(page); onClickEdit = createLineEdit(layout, area->attribute("onClick"), i18n("OnClick:")); onDblClickEdit = createLineEdit(layout, area->attribute("onDblClick"), i18n("OnDblClick:")); onMouseDownEdit = createLineEdit(layout, area->attribute("onMouseDown"), i18n("OnMouseDown:")); onMouseUpEdit = createLineEdit(layout, area->attribute("onMouseUp"), i18n("OnMouseUp:")); onMouseOverEdit = createLineEdit(layout, area->attribute("onMouseOver"), i18n("OnMouseOver:")); onMouseMoveEdit = createLineEdit(layout, area->attribute("onMouseMove"), i18n("OnMouseMove:")); onMouseOutEdit = createLineEdit(layout, area->attribute("onMouseOut"), i18n("OnMouseOut:")); return page; } AreaDialog::AreaDialog(KImageMapEditor* parent, Area* a) : QDialog(parent->widget()) { setWindowTitle(i18n("Area Tag Editor")); // setFaceType( KPageDialog::Tabbed ); setObjectName( "Area Tag Editor" ); setModal(true); _document = parent; if (!a) { slotCancel(); return; } area = a; QString shape("Default"); areaCopy = a->clone(); oldArea = new Area(); oldArea->setRect( a->rect() ); switch (a->type()) { case Area::Rectangle: shape = i18n("Rectangle"); break; case Area::Circle: shape = i18n("Circle"); break; case Area::Polygon: shape = i18n("Polygon"); break; case Area::Selection: shape = i18n("Selection"); break; default: break; } QVBoxLayout *layout = new QVBoxLayout(this); // To get a margin around everything layout->setMargin(5); QLabel *lbl = new QLabel(""+shape+""); lbl->setTextFormat(Qt::RichText); layout->addWidget(lbl); QFrame *line = new QFrame; line->setFrameStyle(QFrame::HLine | QFrame::Sunken); line->setFixedHeight(10); layout->addWidget(line); QTabWidget *tab = new QTabWidget; tab->addTab(createGeneralPage(), i18n("&General")); layout->addWidget(tab); if (a->type() == Area::Default) { // FIXME? Why this useless assignment? shape = i18n("Default"); } else { tab->addTab(createCoordsPage(), i18n("Coor&dinates")); } tab->addTab(createJavascriptPage(), i18n("&JavaScript")); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); layout->addWidget(buttonBox); connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotOk())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(slotCancel())); connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApply())); setMinimumHeight(360); setMinimumWidth(327); resize(327,360); } AreaDialog::~AreaDialog() { delete areaCopy; delete oldArea; } CoordsEdit* AreaDialog::createCoordsEdit(QWidget *parent, Area *a) { if (!a) return 0; switch (a->type()) { case Area::Rectangle : return new RectCoordsEdit(parent,a); break; case Area::Circle : return new CircleCoordsEdit(parent,a); break; case Area::Polygon : return new PolyCoordsEdit(parent,a); break; case Area::Selection : return new SelectionCoordsEdit(parent,a); break; case Area::Default : return new CoordsEdit(parent,a); break; default : return new CoordsEdit(parent,a);break; } } void AreaDialog::slotChooseHref() { - QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Choose File"), QString(), i18n("All Files (*)")); + QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Choose File"), QUrl(), i18n("All Files (*)")); if (!url.isEmpty()) { hrefEdit->setText(url.url()); } } void AreaDialog::slotOk() { if (area) { area->highlightSelectionPoint(-1); if (area->type()==Area::Default) area->setFinished(defaultAreaChk->isChecked()); } slotApply(); accept(); } void AreaDialog::slotApply() { if (area) { if (area->type()!=Area::Default) coordsEdit->applyChanges(); area->setAttribute("href",hrefEdit->text()); area->setAttribute("alt",altEdit->text()); area->setAttribute("target",targetEdit->text()); area->setAttribute("title",titleEdit->text()); area->setAttribute("onclick",onClickEdit->text()); area->setAttribute("ondblclick",onDblClickEdit->text()); area->setAttribute("onmousedown",onMouseDownEdit->text()); area->setAttribute("onmouseup",onMouseUpEdit->text()); area->setAttribute("onmousemove",onMouseMoveEdit->text()); area->setAttribute("onmouseover",onMouseOverEdit->text()); area->setAttribute("onmouseout",onMouseOutEdit->text()); // redraw old area to get rid of it emit areaChanged(oldArea); // draw new area emit areaChanged(area); oldArea->setRect(area->rect()); } } void AreaDialog::slotCancel() { if (area) { AreaSelection *selection=0L; if ( (selection=dynamic_cast(areaCopy)) ) area->setArea(*selection); else area->setArea(*areaCopy); area->highlightSelectionPoint(-1); emit areaChanged(oldArea); emit areaChanged(area); } reject(); } void AreaDialog::slotUpdateArea() { emit areaChanged(oldArea); // draw new area emit areaChanged(area); oldArea->setRect(area->rect()); } PreferencesDialog::PreferencesDialog(QWidget *parent, KConfig* conf) : QDialog(parent) { config = conf; setWindowTitle(i18n("Preferences")); setModal(true); QVBoxLayout *mainLayout = new QVBoxLayout(this); QFormLayout *optionsLayout = new QFormLayout; mainLayout->addLayout(optionsLayout); rowHeightSpinBox = new QSpinBox; int maxPrevHeight = config->group("Appearance").readEntry("maximum-preview-height",50); rowHeightSpinBox->setMaximum(1000); rowHeightSpinBox->setMinimum(15); rowHeightSpinBox->setFixedWidth(60); rowHeightSpinBox->setValue(maxPrevHeight); optionsLayout->addRow(i18n("&Maximum image preview height:"), rowHeightSpinBox); KConfigGroup general = config->group("General"); undoSpinBox = new QSpinBox; undoSpinBox->setFixedWidth(60); undoSpinBox->setMaximum(100); undoSpinBox->setMinimum(1); undoSpinBox->setValue(general.readEntry("undo-level",20)); optionsLayout->addRow(i18n("&Undo limit:"), undoSpinBox); redoSpinBox = new QSpinBox; redoSpinBox->setFixedWidth(60); redoSpinBox->setMaximum(100); redoSpinBox->setMinimum(1); redoSpinBox->setValue(general.readEntry("redo-level",20)); optionsLayout->addRow(i18n("&Redo limit:"), redoSpinBox); startWithCheck = new QCheckBox(i18n("On")); startWithCheck->setChecked(general.readEntry("start-with-last-used-document",true)); optionsLayout->addRow(i18n("&Start with last used document"), startWithCheck); /* colorizeAreaChk = new QCheckBox(i18n("On")); colorizeAreaChk->setFixedWidth(60); colorizeAreaChk->setChecked(KSharedConfig::openConfig()->readEntry("highlightareas",true)); optionsLayout->addRow(i18n("Highlight Areas"), colorizeAreaChk); showAltChk = new QCheckBox(i18n("On")); showAltChk->setFixedWidth(60); showAltChk->setChecked(KSharedConfig::openConfig()->readEntry("showalt",true)); optionsLayout->addRow(i18n("Show alternative text"), showAltChk); */ QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply); mainLayout->addWidget(buttonBox); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotOk())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(buttonBox->button(QDialogButtonBox::Apply),SIGNAL(clicked()),this,SLOT(slotApply())); } PreferencesDialog::~PreferencesDialog() { } void PreferencesDialog::slotDefault( void ) { rowHeightSpinBox->setValue(50); } void PreferencesDialog::slotOk( void ) { slotApply(); accept(); } void PreferencesDialog::slotApply( void ) { KConfigGroup group = config->group("Appearance"); group.writeEntry("maximum-preview-height",rowHeightSpinBox->cleanText().toInt()); group = config->group("General Options"); group.writeEntry("undo-level",undoSpinBox->cleanText().toInt()); group.writeEntry("redo-level",redoSpinBox->cleanText().toInt()); group.writeEntry("start-with-last-used-document", startWithCheck->isChecked()); config->sync(); emit preferencesChanged(); } HTMLPreviewDialog::HTMLPreviewDialog(QWidget* parent, const QString & htmlCode) : QDialog(parent) { tempFile = new QTemporaryFile(QDir::tempPath() + QLatin1String("/kime_preview_XXXXXX.html")); tempFile->open(); setWindowTitle(i18n("Preview")); setModal(true); QTextStream stream(tempFile); stream << htmlCode; qCDebug(KIMAGEMAPEDITOR_LOG) << "HTMLPreviewDialog: TempFile : " << tempFile->fileName(); stream.flush(); QVBoxLayout *mainLayout = new QVBoxLayout(this); htmlPart = new KHTMLPart; mainLayout->addWidget(htmlPart->widget()); // htmlView = new KHTMLView(htmlPart, page); // mainLayout->addWidget(htmlView); // htmlView->setVScrollBarMode(QScrollView::Auto); // htmlView->setHScrollBarMode(QScrollView::Auto); // dialog->resize(dialog->calculateSize(edit->maxLineWidth(),edit->numLines()*)); // dialog->adjustSize(); htmlPart->openUrl(QUrl::fromLocalFile(tempFile->fileName())); QLabel *lbl = new QLabel; lbl->setObjectName( "urllabel" ); mainLayout->addWidget(lbl); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); mainLayout->addWidget(buttonBox); connect( htmlPart, SIGNAL(onURL(QString)), lbl, SLOT(setText(QString))); resize(800,600); } HTMLPreviewDialog::~HTMLPreviewDialog() { delete tempFile; delete htmlPart; } diff --git a/kimeshell.cpp b/kimeshell.cpp index 2b553c7..b354405 100644 --- a/kimeshell.cpp +++ b/kimeshell.cpp @@ -1,287 +1,287 @@ /*************************************************************************** kimepart.cpp - description ------------------- begin : Mon Aug 5 2002 copyright : (C) 2002 by Jan Schäfer email : janschaefer@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program 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 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "kimeshell.h" #include #include #include #include #include #include #include #include "kimagemapeditor_debug.h" #include #include #include #include #include #include #include #include #include #include #include #include "drawzone.h" #include "kimagemapeditor.h" // the KPart KimeShell::KimeShell(const char * ) : KParts::MainWindow() { setXMLFile("kimagemapeditorui.rc"); // QDockWidget* mainDock = new QDockWidget(this); // mainDock = createDockWidget( "MainDockWidget", 0L, 0L, "main_dock_widget"); // QWidget *mainWidget = new KHBox( this ); // QScrollArea* mainWidget = new QScrollArea(this); // setCentralWidget(mainWidget); // QLayout* layout = new QGridLayout( mainDock ); // mainDock->setWidget( w ); // allow others to dock to the 4 sides // mainDock->setDockSite(K3DockWidget::DockCorner); // forbid docking abilities of mainDock itself // mainDock->setEnableDocking(K3DockWidget::DockNone); // setView( mainDock); // central widget in a KDE mainwindow // setMainDockWidget( mainDock); // master dockwidget qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 0"; m_part = new KImageMapEditor((QWidget*)0L, this); // setCentralWidget( part->widget() ); qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 1"; setupActions(); qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 2"; _stdout=false; // createGUI( part ); createShellGUI( true ); guiFactory()->addClient( m_part ); KParts::GUIActivateEvent ev( true ); QApplication::sendEvent( m_part, &ev ); //setCentralWidget(part->widget()); qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 3"; resize( QSize(725, 525).expandedTo(minimumSizeHint())); connect( m_part, SIGNAL(setStatusBarText(QString)), this, SLOT(slotSetStatusBarText(QString))); connect( m_part, SIGNAL(setWindowCaption(QString)), this, SLOT(setWindowTitle(QString))); setAutoSaveSettings( "General Options" ); qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 4"; } KimeShell::~KimeShell() { // delete part; } bool KimeShell::queryClose() { if (_stdout) { //FIXME std::cout << m_part->getHtmlCode() << std::endl; } return m_part->queryClose(); } bool KimeShell::queryExit() { // writeConfig(); #ifdef __GNUC__ #warning what group is correct here? A random one? #endif KConfigGroup cg( KSharedConfig::openConfig(), QString() ); saveProperties( cg ); return true; } void KimeShell::setupActions() { (void)KStandardAction::openNew(this, SLOT(fileNew()), actionCollection()); // File Quit (void)KStandardAction::quit(this, SLOT(close()),actionCollection()); //FIXME (void)KStandardAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection()); (void)KStandardAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection()); (void)KStandardAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection()); (void)KStandardAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection()); } void KimeShell::fileNew() { // this slot is called whenever the File->New menu is selected, // the New shortcut is pressed (usually CTRL+N) or the New toolbar // button is clicked // About this function, the style guide ( // http://developer.kde.org/documentation/standards/kde/style/basics/index.html ) // says that it should open a new window if the document is _not_ // in its initial state. This is what we do here.. if ( ! m_part->url().isEmpty() || m_part->isModified() ) { KimeShell * newShell = new KimeShell(); newShell->show(); newShell->readConfig(); }; } void KimeShell::openFile(const QUrl & url) { m_part->openFile(url); } void KimeShell::openLastFile() { #ifdef __GNUC__ #warning there is no group defined #endif KConfigGroup cg( m_part->config(), QString() ); if (cg.readEntry("start-with-last-used-document",true)) m_part->openLastURL( cg ); } void KimeShell::fileOpen() { - QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Choose Picture to Open"), QString(), + QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Choose Picture to Open"), QUrl(), i18n("Web File (*.png *.jpg *.jpeg *.gif *.htm *.html);;Images (*.png *.jpg *.jpeg *.gif *.bmp *.xbm *.xpm *.pnm *.mng);;" "HTML Files (*.htm *.html);;All Files (*)")); if (!url.isEmpty()) { // About this function, the style guide ( // http://developer.kde.org/documentation/standards/kde/style/basics/index.html ) // says that it should open a new window if the document is _not_ // in its initial state. This is what we do here.. if ( m_part->url().isEmpty() && ! m_part->isModified() ) { // we open the file in this window... m_part->openURL(url); } else { // we open the file in a new window... KimeShell* newWin = new KimeShell; newWin->openFile( url ); newWin->show(); } } } void KimeShell::readConfig() { KSharedConfigPtr config = KSharedConfig::openConfig(); readConfig(config->group("General Options") ); } void KimeShell::readConfig(const KConfigGroup &) { // applyMainWindowSettings(config); // restoreWindowSize(config); // readDockConfig(config); } void KimeShell::writeConfig() { KConfigGroup config( KSharedConfig::openConfig(), "General Options"); writeConfig( config ); } void KimeShell::writeConfig(KConfigGroup &config) { saveMainWindowSettings(config); KWindowConfig::saveWindowSize(windowHandle(), config); // writeDockConfig(config); config.sync(); } void KimeShell::saveProperties(KConfigGroup &config) { //writeConfig(config); m_part->saveProperties(config); writeConfig(); } void KimeShell::readProperties(const KConfigGroup &config) { readConfig(); m_part->readProperties(config); } void KimeShell::optionsConfigureKeys() { // KShortcutsDialog::configureKeys(actionCollection(), "testprog_shell.rc"); KShortcutsDialog dlg; dlg.addCollection(actionCollection()); dlg.addCollection(m_part->actionCollection()); dlg.configure(); } void KimeShell::optionsConfigureToolbars() { KConfigGroup configGroup = KSharedConfig::openConfig()->group(autoSaveGroup()); saveMainWindowSettings(configGroup); // use the standard toolbar editor KEditToolBar dlg(factory()); connect(&dlg, SIGNAL(newToolbarConfig()), this, SLOT(applyNewToolbarConfig())); dlg.exec(); } void KimeShell::applyNewToolbarConfig() { KConfigGroup configGroup = KSharedConfig::openConfig()->group(autoSaveGroup()); applyMainWindowSettings(configGroup); } void KimeShell::optionsShowToolbar() { if (toolBar()->isVisible()) toolBar()->hide(); else toolBar()->show(); } void KimeShell::optionsShowStatusbar() { if (statusBar()->isVisible()) statusBar()->hide(); else statusBar()->show(); } diff --git a/org.kde.kimagemapeditor.appdata.xml b/org.kde.kimagemapeditor.appdata.xml index f6e4e96..98daf6c 100644 --- a/org.kde.kimagemapeditor.appdata.xml +++ b/org.kde.kimagemapeditor.appdata.xml @@ -1,133 +1,134 @@ org.kde.kimagemapeditor.desktop FSFAP GPL-2.0+ KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KCitraMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor KImageMapEditor Kimagemapeditor KImageMapEditor xxKImageMapEditorxx KImageMapEditor KImageMapEditor HTML Image Map Editor Un editor de correspondències a imatges amb HTML Un editor de correspondències a imatges amb HTML Editor HTML map HTML-billedkortredigering Editor für HTML-Bildkarten (Imagemaps) Επεξεργαστής χάρτη εικόνας HTML HTML Image Map Editor Editor de mapas de imágenes en HTML HTML irudi-mapa editorea HTML-kuvamuokkain Éditeur de carte d'images HTML Editor de mapas de imaxes HTML Pengedit Peta Citra HTML Editor di mappe immagine HTML HTML 이미지 맵 편집기 HTML bewerker van afbeeldingskaarten HTML-biletkartredigering Edytor mapy obrazu HTML Editor de Mapas de Imagens HTML Editor de mapeamento de imagem HTML HTML Image Map Editor Editor HTML mapy obrázkov Urejevalnik slikovnih zemljevidov za HTML Redigering av HTML-bildkartor Редактор карт зображень HTML xxHTML Image Map Editorxx HTML 图像映射编辑器 HTML 影像地圖編輯器

KImageMapEditor is an editor of image maps embedded inside HTML files, based on the <map> tag.

El KImageMapEditor és un editor de correspondències a imatges incrustades dins de fitxers HTML, basat en l'etiqueta <map>.

El KImageMapEditor és un editor de correspondències a imatges incrustades dins de fitxers HTML, basat en l'etiqueta <map>.

KImageMapEditor er en editor til billedkort som er indlejret i HTML-filer, baseret på <map>-opmærkning.

KImageMapEditor ist ein Editor für Bildkarten, die in HTML eingebettet sind.

Το KImageMapEditor είναι επεξεργαστής εικόνων χαρτών ενσωματωμένος μέσα σε αρχεία HTML, με βάση την ετικέτα <map>.

KImageMapEditor is an editor of image maps embedded inside HTML files, based on the <map> tag.

KImageMapEditor es un editor de mapas de imágenes integradas en el interior de archivos HTML que usan la etiqueta <map>.

KImageMapEditor HTML fitxategien barruan txertatutako irudi-mapen editore bat da, <map> etiketa du jomuga.

KImageMapEditor on HTML-tiedostoihin upotettujen <map>-tunnisteeseen perustuvien kuvakarttojen muokkain.

KImageMapEditor est un éditeur de cartes d'images intégrées au sein de fichiers HTML, faisant appel à la balise <map>.

KImageMapEditor é un editor de mapas de imaxe incrustados dentro de ficheiros HTML, baseado na etiqueta <map>.

KCitraMapEditor adalah editor peta citra yang disematkan dalam file HTML, berdasarkan pada tag <map>.

KImageMapEditor è un editor di mappe immagine incorporate all'interno dei file HTML e basate sul tag <map>.

KImageMapEditor는 HTML 파일의 <map> 태그를 기반으로 한 이미지 맵 편집기입니다.

KImageMapEditor is een bewerker van afbeeldingskaarten ingebed in HTML-bestanden, gebaseerd op de tag <map>.

KImageMapEditor er eit redigeringsprogram for biletkart (<map>-elementet) i HTML-filer.

KImageMapEditor jest edytorem map obrazów osadzonych wewnątrz plików HTML i opartym na znaczniku <map>.

O KImageMapEditor é um editor de mapas de imagens incorporados dentro dos ficheiros HTML, baseado na marca <map>.

KImageMapEditor é um editor de mapas de imagens incorporado dentro de arquivos HTML, com base na tag <map>.

KImageMapEditor — редактор разметки HTML-карт изображений, основанных на использовании тега <map>.

KImageMapEditor je editor obrazových máp vložených do HTML súborov, založený na tagu <map>.

KImageMapEditor je urejevalnik slikovnih zemljevidov, ki so v obliki oznak <map> vgrajeni znotraj datotek HTML.

Kimagemapeditor är en editor av bildkartor inbäddade i HTML-filer, baserade på taggen <map>.

KImageMapEditor — редактор карт зображень, які вбудовуються до файлів HTML і працюють на основі теґу <map>.

xxKImageMapEditor is an editor of image maps embedded inside HTML files, based on the <map> tag.xx

KImageMapEditor 是一个编辑 HTML 文件中的映射图 (image map) 的编辑器,它们用 <map> 标签表示。

KImageMapEditor 是個可以編輯嵌入在 HTML 檔案中影像地圖的編輯器,基於 <map> 標籤。

Editing HTML image map in KImageMapEditor Editant una correspondència a imatge amb HTML al KImageMapEditor Editant una correspondència a imatge amb HTML al KImageMapEditor Úprava obrázkových map HTML pomocí KImageMapEditor Redigering af HTML-billedkort i KImageMapEditor Bearbeitung von HTML-Bildkarten (Imagemaps) in KImageMapEditor Επεξεργασία χάρτη εικόνας HTML στο KImageMapEditor Editing HTML image map in KImageMapEditor Editando un mapa de imagen HTML en KImageMapEditor KImageMapEditor erabiliz HTML irudi-mapa editatzea HTML-kuvakartan muokkaus KImageMapEditorissa Édition d'une carte d'image HTML dans KImageMapEditor Editando un mapa de imaxe de HTML en KImageMapEditor Mengedit peta citra HTML di KCitraMapEditor Modifica di una mappa immagine HTML in KImageMapEditor KImageMapEditor로 HTML 이미지 맵 편집 HTML imagemap bewerken in KImageMapEditor Redigering av HTML-biletkart med KImageMapEditor Edytowanie mapy obrazu HTML w KImageMapEditor Edição de um mapa de imagens HTML no KImageMapEditor Editando mapeamento de imagem HTML no KImageMapEditor Редактирование HTML-разметки карты изображения в KImageMapEditor + Editor HTML mapy obrázkov v KImageMapEditor Redigering av HTML-bildkarta i KImagemapeditor Редагування HTML-карти зображення у KImageMapEditor xxEditing HTML image map in KImageMapEditorxx 在 KImageMapEditor 中編輯 HTML 影像地圖 https://www.kde.org/images/screenshots/kimagemapeditor.png https://www.kde.org/applications/development/kimagemapeditor/ https://bugs.kde.org/enter_bug.cgi?format=guided&product=kimagemapeditor http://docs.kde.org/?application=kimagemapeditor KDE kimagemapeditor