diff --git a/CMakeLists.txt b/CMakeLists.txt index 47f95ec..2da60bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,116 +1,132 @@ # SPDX-FileCopyrightText: (C) 2008 Kelvie Wong # SPDX-FileCopyrightText: (C) 2014 Gleb Baryshev # SPDX-FileCopyrightText: (C) 2018 Luigi Toscano # # SPDX-License-Identifier: GPL-2.0-or-later +cmake_minimum_required(VERSION 3.5) -cmake_minimum_required(VERSION 2.8.12) -cmake_policy(SET CMP0063 NEW) -set(BASKET_DISABLE_GPG "0" CACHE BOOL "Disables GPG Support") +project(Basket VERSION 2.49.90) -include(FeatureSummary) +set(REQUIRED_KF5_VERSION "5.60.0") +set(REQUIRED_QT5_VERSION "5.12.0") -find_package(X11 REQUIRED) +# Options +option(ENABLE_GPG "Enabled GPG Support" OFF) +option(ENABLE_KPARTS "Add Kontact integration (currently broken)" OFF) -# KDE +# ECM +include(FeatureSummary) find_package(ECM REQUIRED NO_MODULE) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH}) +set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://commits.kde.org/extra-cmake-modules") +feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") -IF(NOT BASKET_DISABLE_GPG) - find_package(Gpgme) -ENDIF(NOT BASKET_DISABLE_GPG) - -# libgit2 -find_package(Libgit2) -IF(LIBGIT2_FOUND) - include_directories(${LIBGIT2_INCLUDE_DIR}) - add_definitions(-DWITH_LIBGIT2) -ELSE(LIBGIT2_FOUND) - message("libgit2 not found, configuring without") -ENDIF(LIBGIT2_FOUND) - - - -if (BUILD_KPARTS) -find_package(KdepimLibs REQUIRED) -include_directories(${KDEPIMLIBS_INCLUDE_DIRS}) -endif (BUILD_KPARTS) - -find_package(Qt5 REQUIRED COMPONENTS - Concurrent - Core - DBus - Gui - Widgets - Xml -) +set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/Modules) +include(ECMSetupVersion) +include(KDEInstallDirs) +include(KDECMakeSettings) include(KDEClangFormat) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDEInstallDirs) include(ECMInstallIcons) -include(KDECMakeSettings) -find_package(KF5 REQUIRED COMPONENTS - Archive - Completion - Config - ConfigWidgets #KCM - CoreAddons - Crash - DBusAddons - DocTools - FileMetaData - GlobalAccel - GuiAddons - I18n - IconThemes - KCMUtils - KIO - Notifications - Parts - Service - TextWidgets - WidgetsAddons - WindowSystem - XmlGui +ecm_setup_version( + PROJECT + VARIABLE_PREFIX BASKET + VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/basket_version.h") + +# GPG +if (ENABLE_GPG) + find_package(Gpgme) +endif() + +# libgit2 +find_package(Libgit2) +set_package_properties(Kibgit2 PROPERTIES DESCRIPTION "A library to manipulate git repositories" + PURPOSE "Add git suppor to Basket" + URL "https://libgit2.org" + TYPE OPTIONAL +) +if (LIBGIT2_FOUND) + include_directories(${LIBGIT2_INCLUDE_DIR}) + add_definitions(-DWITH_LIBGIT2) +endif() + +# TODO make X11 optional +find_package(X11 REQUIRED) + +if (ENABLE_KPARTS) + find_package(KdepimLibs REQUIRED) + include_directories(${KDEPIMLIBS_INCLUDE_DIRS}) +endif() + +find_package(Qt5 ${REQUIRED_QT5_VERSION} REQUIRED COMPONENTS + Concurrent + Core + DBus + Gui + Widgets + Xml +) + +find_package(KF5 ${REQUIRED_KF5_VERSION} REQUIRED COMPONENTS + Archive + Completion + Config + ConfigWidgets #KCM + CoreAddons + Crash + DBusAddons + DocTools + FileMetaData + GlobalAccel + GuiAddons + I18n + IconThemes + KCMUtils + KIO + Notifications + Parts + Service + TextWidgets + WidgetsAddons + WindowSystem + XmlGui ) find_package(Phonon4Qt5 REQUIRED) -IF(GPGME_FOUND) - SET(HAVE_LIBGPGME 1) - SET(LARGEFILE_SOURCE_1) - ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64) -ELSE(GPGME_FOUND) - IF (BASKET_DISABLE_GPG) - MESSAGE("GPG disabled, configuring without") - ELSE (BASKET_DISABLE_GPG) - MESSAGE("GPG not found, configuring without") - ENDIF (BASKET_DISABLE_GPG) -ENDIF(GPGME_FOUND) +if (GPGME_FOUND) + set(HAVE_LIBGPGME 1) + SET(LARGEFILE_SOURCE_1) + ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64) +else() + if (BASKET_DISABLE_GPG) + MESSAGE("GPG disabled, configuring without") + else() + MESSAGE("GPG not found, configuring without") + endif() +endif() + #TODO: find meinproc #Make libbasketcommon search for translations in basket.mo -ADD_DEFINITIONS(-DTRANSLATION_DOMAIN=\"basket\") +add_definitions(-DTRANSLATION_DOMAIN=\"basket\") -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(doc) add_subdirectory(src) add_subdirectory(tags) add_subdirectory(welcome) add_subdirectory(backgrounds) add_subdirectory(images) add_subdirectory(file-integration) ki18n_install(po) # add clang-format target for all our real source files file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) - -feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5548083..83b370b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,160 +1,170 @@ include_directories(${GPGME_INCLUDES}) ########### next target ############### -set(basketcommon_LIB_SRCS +set(libbasket_SRCS aboutdata.cpp archive.cpp backgroundmanager.cpp backup.cpp basketfactory.cpp basketlistview.cpp basketproperties.cpp basketscene.cpp basketstatusbar.cpp basketview.cpp bnpview.cpp colorpicker.cpp crashhandler.cpp debugwindow.cpp decoratedbasket.cpp diskerrordialog.cpp file_metadata.cpp filter.cpp focusedwidgets.cpp formatimporter.cpp global.cpp gitwrapper.cpp htmlexporter.cpp history.cpp kcolorcombo2.cpp kgpgme.cpp likeback.cpp linklabel.cpp newbasketdialog.cpp note.cpp notecontent.cpp notedrag.cpp noteedit.cpp notefactory.cpp noteselection.cpp password.cpp regiongrabber.cpp settings.cpp settings_versionsync.cpp softwareimporters.cpp systemtray.cpp tag.cpp tagsedit.cpp transparentwidget.cpp tools.cpp variouswidgets.cpp xmlwork.cpp ) set(PIMO_CPP "") # One of the generated files ki18n_wrap_ui(basket_FORM_HDRS passwordlayout.ui basketproperties.ui settings_versionsync.ui) -qt5_add_dbus_adaptor(basketcommon_LIB_SRCS org.kde.basket.BNPView.xml bnpview.h BNPView) - -QT5_ADD_RESOURCES(basket_RESOURCES ../basket.qrc) - -add_library(basketcommon SHARED ${basketcommon_LIB_SRCS} ${basket_FORM_HDRS} ${basket_RESOURCES}) - -target_link_libraries(basketcommon - ${PHONON_LIBRARY} - ${GPGME_VANILLA_LIBRARIES} - KF5::Archive - KF5::ConfigWidgets - KF5::CoreAddons - KF5::Crash - KF5::DBusAddons - KF5::FileMetaData - KF5::GlobalAccel - KF5::GuiAddons - KF5::I18n - KF5::IconThemes - KF5::KCMUtils - KF5::KIOWidgets - KF5::Notifications - KF5::Parts - KF5::TextWidgets - KF5::WindowSystem - KF5::XmlGui +qt5_add_dbus_adaptor(libbasket_SRCS org.kde.basket.BNPView.xml bnpview.h BNPView) + +qt5_add_resources(basket_RESOURCES ../basket.qrc) + +add_library(LibBasket SHARED ${libbasket_SRCS} ${basket_FORM_HDRS} ${basket_RESOURCES}) + +target_link_libraries(LibBasket + ${PHONON_LIBRARY} + ${GPGME_VANILLA_LIBRARIES} + KF5::Archive + KF5::ConfigWidgets + KF5::CoreAddons + KF5::Crash + KF5::DBusAddons + KF5::FileMetaData + KF5::GlobalAccel + KF5::GuiAddons + KF5::I18n + KF5::IconThemes + KF5::KCMUtils + KF5::KIOWidgets + KF5::Notifications + KF5::Parts + KF5::TextWidgets + KF5::WindowSystem + KF5::XmlGui ) -set_target_properties(basketcommon PROPERTIES VERSION ${Qt5Core_VERSION} SOVERSION ${Qt5Core_VERSION_MAJOR}) +set_target_properties(LibBasket PROPERTIES + VERSION + ${Qt5Core_VERSION} + SOVERSION + ${Qt5Core_VERSION_MAJOR} +) -install(TARGETS basketcommon DESTINATION ${LIB_INSTALL_DIR}) +install(TARGETS LibBasket DESTINATION ${LIB_INSTALL_DIR}) # Add unit tests after all variables have been set. # If we save target_link_libraries to a variable, we can reuse it too -# Soprano files must exist, otherwise tests won't build -#set(FILES_GENERATED (EXISTS ${PIMO_CPP})) -#if(${FILES_GENERATED}) - add_subdirectory(tests EXCLUDE_FROM_ALL) -#endif(${FILES_GENERATED}) +if (BUILD_TESTING) + add_subdirectory(tests) +endif () ########### next target ############### set(basket_SRCS main.cpp mainwindow.cpp application.cpp) add_executable(basket ${basket_SRCS}) -target_link_libraries(basket - basketcommon) +target_link_libraries(basket LibBasket) -IF(LIBGIT2_FOUND) - target_link_libraries(basketcommon ${LIBGIT2_LIBRARIES}) - target_link_libraries(basket ${LIBGIT2_LIBRARIES}) -ENDIF(LIBGIT2_FOUND) +if (LIBGIT2_FOUND) + target_link_libraries(LibBasket ${LIBGIT2_LIBRARIES}) + target_link_libraries(basket ${LIBGIT2_LIBRARIES}) +endif() install(TARGETS basket DESTINATION ${BIN_INSTALL_DIR}) ########### next target ############### set(kcm_basket_PART_SRCS kcm_basket.cpp) add_library(kcm_basket MODULE ${kcm_basket_PART_SRCS}) -target_link_libraries(kcm_basket basketcommon) +target_link_libraries(kcm_basket LibBasket) install(TARGETS kcm_basket DESTINATION ${PLUGIN_INSTALL_DIR}) -if(BUILD_KPARTS) +if (ENABLE_KPARTS) -########### next target ############### + ########### next target ############### -set(basketpart_PART_SRCS basket_part.cpp) + set(basketpart_PART_SRCS basket_part.cpp) -set_target_properties(basketpart PROPERTIES PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}") -add_library(basketpart MODULE ${basketpart_PART_SRCS}) + set_target_properties(basketpart PROPERTIES PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}") + add_library(basketpart MODULE ${basketpart_PART_SRCS}) -target_link_libraries(basketpart basketcommon kparts kdeui) + target_link_libraries(basketpart LibBasket Kparts KDEUI) -install(TARGETS basketpart DESTINATION ${PLUGIN_INSTALL_DIR}) + install(TARGETS basketpart DESTINATION ${PLUGIN_INSTALL_DIR}) -set(kontact_basket_PLUGIN_SRCS basket_plugin.cpp) + set(kontact_basket_PLUGIN_SRCS basket_plugin.cpp) -add_library(kontact_basketplugin MODULE ${kontact_basket_PLUGIN_SRCS}) + add_library(kontact_basketplugin MODULE ${kontact_basket_PLUGIN_SRCS}) -add_dependencies(kontact_basketplugin basket) + add_dependencies(kontact_basketplugin basket) -target_link_libraries(kontact_basketplugin basketcommon) + target_link_libraries(kontact_basketplugin basketcommon) -install(TARGETS kontact_basketplugin DESTINATION ${PLUGIN_INSTALL_DIR}) -install(FILES basket_plugin.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kontact) + install(TARGETS kontact_basketplugin DESTINATION ${PLUGIN_INSTALL_DIR}) + install(FILES basket_plugin.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kontact) -########### install files ############### + ########### install files ############### -install(FILES basket_part.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/basket) -install(FILES basket_part.desktop DESTINATION ${SERVICES_INSTALL_DIR}) + install(FILES basket_part.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/basket) + install(FILES basket_part.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +endif() -endif(BUILD_KPARTS) +set(DESKTOP_FILES + basket_config_general.desktop + basket_config_baskets.desktop + basket_config_new_notes.desktop + basket_config_notes_appearance.desktop + basket_config_apps.desktop + basket_config_version_sync.desktop +) install(FILES org.kde.basket.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) install(FILES org.kde.basket.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) -install(FILES basket_config_general.desktop basket_config_baskets.desktop basket_config_new_notes.desktop basket_config_notes_appearance.desktop basket_config_apps.desktop basket_config_version_sync.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +install(FILES ${DESKTOP_FILES} DESTINATION ${SERVICES_INSTALL_DIR}) install(FILES basketui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/basket) diff --git a/src/notecontent.h b/src/notecontent.h index f7fbcfa..256586b 100644 --- a/src/notecontent.h +++ b/src/notecontent.h @@ -1,947 +1,948 @@ /** * SPDX-FileCopyrightText: (C) 2003 Sébastien Laoût * * SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef NOTECONTENT_H #define NOTECONTENT_H #include #include #include #include #include #include +#include "basket_export.h" #include "linklabel.h" class QDomElement; class QBuffer; class QColor; class QMimeData; class QMovie; class QPainter; class QPixmap; class QPoint; class QRect; class QString; class QStringList; class QTextDocument; class QWidget; class KFileItem; class QUrl; namespace KIO { class PreviewJob; } namespace Phonon { class MediaObject; } class BasketScene; class FilterData; class Note; /** * LinkDisplayItem is a QGraphicsItem using a LinkDisplay */ class LinkDisplayItem : public QGraphicsItem { public: explicit LinkDisplayItem(Note *parent) : m_note(parent) { } ~LinkDisplayItem() override { } QRectF boundingRect() const override; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; LinkDisplay &linkDisplay() { return m_linkDisplay; } private: LinkDisplay m_linkDisplay; Note *m_note; }; /** A list of numeric identifier for each note type. * Declare a variable with the type NoteType::Id and assign a value like NoteType::Text... * @author Sébastien Laoût */ namespace NoteType { enum Id { Group = 255, Text = 1, Html, Image, Animation, Sound, File, Link, CrossReference, Launcher, Color, Unknown }; // Always positive } /** Abstract base class for every content type of basket note. * It's a base class to represent those types: Text, Html, Image, Animation, Sound, File, Link, Launcher, Color, Unknown. * @author Sébastien Laoût */ -class NoteContent +class BASKET_EXPORT NoteContent { public: // Constructor and destructor: explicit NoteContent(Note *parent, const QString &fileName = QString()); /// << Constructor. Inherited notes should call it to initialize the parent note. virtual ~NoteContent() { } /// << Virtual destructor. Reimplement it if you should destroy some data your custom types. // Simple Abstract Generic Methods: virtual NoteType::Id type() const = 0; /// << @return the internal number that identify that note type. virtual QString typeName() const = 0; /// << @return the translated type name to display in the user interface. virtual QString lowerTypeName() const = 0; /// << @return the type name in lowercase without space, for eg. saving. virtual QString toText(const QString &cuttedFullPath); /// << @return a plain text equivalent of the content. virtual QString toHtml(const QString &imageName, const QString &cuttedFullPath) = 0; /// << @return an HTML text equivalent of the content. @param imageName Save image in this Qt resource. virtual QPixmap toPixmap() { return QPixmap(); } /// << @return an image equivalent of the content. virtual void toLink(QUrl *url, QString *title, const QString &cuttedFullPath); /// << Set the link to the content. By default, it set them to fullPath() if useFile(). virtual bool useFile() const = 0; /// << @return true if it use a file to store the content. virtual bool canBeSavedAs() const = 0; /// << @return true if the content can be saved as a file by the user. virtual QString saveAsFilters() const = 0; /// << @return the filters for the user to choose a file destination to save the note as. virtual bool match(const FilterData &data) = 0; /// << @return true if the content match the filter criteria. // Complex Abstract Generic Methods: virtual void exportToHTML(HTMLExporter *exporter, int indent) = 0; /// << Export the note in an HTML file. virtual QString cssClass() const = 0; /// << @return the CSS class of the note when exported to HTML virtual qreal setWidthAndGetHeight(qreal width) = 0; /// << Relayout content with @p width (never less than minWidth()). @return its new height. virtual bool loadFromFile(bool /*lazyLoad*/) { return false; } /// << Load the content from the file. The default implementation does nothing. @see fileName(). virtual bool finishLazyLoad() { return false; } /// << Load what was not loaded by loadFromFile() if it was lazy-loaded virtual bool saveToFile() { return false; } /// << Save the content to the file. The default implementation does nothing. @see fileName(). virtual QString linkAt(const QPointF & /*pos*/) { return QString(); } /// << @return the link anchor at position @p pos or QString() if there is no link. virtual void saveToNode(QXmlStreamWriter &stream); /// << Save the note in the basket XML file. By default it store the filename if a file is used. virtual void fontChanged() = 0; /// << If your content display textual data, called when the font have changed (from tags or basket font) virtual void linkLookChanged() { } /// << If your content use LinkDisplay with preview enabled, reload the preview (can have changed size) virtual QString editToolTipText() const = 0; /// << @return "Edit this [text|image|...]" to put in the tooltip for the note's content zone. virtual void toolTipInfos(QStringList * /*keys*/, QStringList * /*values*/) { } /// << Get "key: value" couples to put in the tooltip for the note's content zone. // Custom Zones: /// Implement this if you want to store custom data. virtual int zoneAt(const QPointF & /*pos*/) { return 0; } /// << If your note-type have custom zones, @return the zone at @p pos or 0 if it's not a custom zone! virtual QRectF zoneRect(int /*zone*/, const QPointF & /*pos*/); /// << Idem, @return the rect of the custom zone virtual QString zoneTip(int /*zone*/) { return QString(); } /// << Idem, @return the toolTip of the custom zone virtual Qt::CursorShape cursorFromZone(int /*zone*/) const { return Qt::ArrowCursor; } /// << Idem, @return the mouse cursor when it is over zone @p zone! virtual void setHoveredZone(int /*oldZone*/, int /*newZone*/) { } /// << If your note type need some feedback, you get notified of hovering changes here. virtual QString statusBarMessage(int /*zone*/) { return QString(); } /// << @return the statusBar message to show for zone @p zone, or QString() if nothing special have to be said. // Drag and Drop Content: virtual void serialize(QDataStream & /*stream*/) { } /// << Serialize the content in a QDragObject. If it consists of a file, it can be serialized for you. virtual bool shouldSerializeFile() { return useFile(); } /// << @return true if the dragging process should serialize the filename (and move the file if cutting). virtual void addAlternateDragObjects(QMimeData * /*dragObj*/) { } /// << If you offer more than toText/Html/Image/Link(), this will be called if this is the only selected. virtual QPixmap feedbackPixmap(qreal width, qreal height) = 0; /// << @return the pixmap to put under the cursor while dragging this object. virtual bool needSpaceForFeedbackPixmap() { return false; } /// << @return true if a space must be inserted before and after the DND feedback pixmap. // Content Edition: virtual int xEditorIndent() { return 0; } /// << If the editor should be indented (eg. to not cover an icon), return the number of pixels. // Open Content or File: virtual QUrl urlToOpen(bool /*with*/); /// << @return the URL to open the note, or an invalid QUrl if it's not openable. If @p with if false, it's a normal "Open". If it's true, it's for an "Open with..." action. The default /// implementation return the fullPath() if the note useFile() and nothing if not. enum OpenMessage { OpenOne, /// << Message to send to the statusbar when opening this note. OpenSeveral, /// << Message to send to the statusbar when opening several notes of this type. OpenOneWith, /// << Message to send to the statusbar when doing "Open With..." on this note. OpenSeveralWith, /// << Message to send to the statusbar when doing "Open With..." several notes of this type. OpenOneWithDialog, /// << Prompt-message of the "Open With..." dialog for this note. OpenSeveralWithDialog /// << Prompt-message of the "Open With..." dialog for several notes of this type. }; virtual QString messageWhenOpening(OpenMessage /*where*/) { return QString(); } /// << @return the message to display according to @p where or nothing if it can't be done. @see OpenMessage describing the nature of the message that should be returned... The default implementation return an empty string. NOTE: If /// urlToOpen() is invalid and messageWhenOpening() is not empty, then the user will be prompted to edit the note (with the message returned by messageWhenOpening()) for eg. being able to edit URL of a link if it's empty when opening /// it... virtual QString customOpenCommand() { return QString(); } /// << Reimplement this if your urlToOpen() should be opened with another application instead of the default KDE one. This choice should be left to the users in the setting (choice to use a custom app or not, and which app). // Common File Management: /// (and do save changes) and optionally hide the toolbar. virtual void setFileName(const QString &fileName); /// << Set the filename. Reimplement it if you eg. want to update the view when the filename is changed. bool trySetFileName(const QString &fileName); /// << Set the new filename and return true. Can fail and return false if a file with this fileName already exists. QString fullPath(); /// << Get the absolute path of the file where this content is stored on disk. QString fileName() const { return m_fileName; } /// << Get the file name where this content is stored (relative to the basket folder). @see fullPath(). qreal minWidth() const { return m_minWidth; } /// << Get the minimum width for this content. Note *note() { return m_note; } /// << Get the note managing this content. BasketScene *basket(); /// << Get the basket containing the note managing this content. virtual QGraphicsItem *graphicsItem() = 0; public: void setEdited(); /// << Mark the note as edited NOW: change the "last modification time and time" AND save the basket to XML file. protected: void contentChanged(qreal newMinWidth); /// << When the content has changed, inherited classes should call this to specify its new minimum size and trigger a basket relayout. private: Note *m_note; QString m_fileName; qreal m_minWidth; public: static const int FEEDBACK_DARKING; }; /** Real implementation of plain text notes: * @author Sébastien Laoût */ -class TextContent : public NoteContent +class BASKET_EXPORT TextContent : public NoteContent { public: // Constructor and destructor: TextContent(Note *parent, const QString &fileName, bool lazyLoad = false); ~TextContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toText(const QString & /*cuttedFullPath*/) override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal width) override; bool loadFromFile(bool lazyLoad) override; bool finishLazyLoad() override; bool saveToFile() override; QString linkAt(const QPointF &pos) override; void fontChanged() override; QString editToolTipText() const override; // Drag and Drop Content: QPixmap feedbackPixmap(qreal width, qreal height) override; // Open Content or File: QString messageWhenOpening(OpenMessage where) override; // QString customOpenCommand(); // Content-Specific Methods: void setText(const QString &text, bool lazyLoad = false); /// << Change the text note-content and relayout the note. QString text() { return m_graphicsTextItem.text(); } /// << @return the text note-content. QGraphicsItem *graphicsItem() override { return &m_graphicsTextItem; } protected: // QString m_text; // QTextDocument *m_simpleRichText; QGraphicsSimpleTextItem m_graphicsTextItem; }; #include /** Real implementation of rich text (HTML) notes: * @author Sébastien Laoût */ -class HtmlContent : public NoteContent +class BASKET_EXPORT HtmlContent : public NoteContent { public: // Constructor and destructor: HtmlContent(Note *parent, const QString &fileName, bool lazyLoad = false); ~HtmlContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toText(const QString & /*cuttedFullPath*/) override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal width) override; bool loadFromFile(bool lazyLoad) override; bool finishLazyLoad() override; bool saveToFile() override; QString linkAt(const QPointF &pos) override; void fontChanged() override; QString editToolTipText() const override; // Drag and Drop Content: QPixmap feedbackPixmap(qreal width, qreal height) override; // Open Content or File: QString messageWhenOpening(OpenMessage where) override; QString customOpenCommand() override; // Content-Specific Methods: void setHtml(const QString &html, bool lazyLoad = false); /// << Change the HTML note-content and relayout the note. QString html() { return m_html; } /// << @return the HTML note-content. QGraphicsItem *graphicsItem() override { return &m_graphicsTextItem; } protected: QString m_html; QString m_textEquivalent; // OPTIM_FILTER QTextDocument *m_simpleRichText; QGraphicsTextItem m_graphicsTextItem; }; /** Real implementation of image notes: * @author Sébastien Laoût */ -class ImageContent : public NoteContent +class BASKET_EXPORT ImageContent : public NoteContent { public: // Constructor and destructor: ImageContent(Note *parent, const QString &fileName, bool lazyLoad = false); ~ImageContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; QPixmap toPixmap() override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal width) override; bool loadFromFile(bool lazyLoad) override; bool finishLazyLoad() override; bool saveToFile() override; void fontChanged() override; QString editToolTipText() const override; void toolTipInfos(QStringList *keys, QStringList *values) override; // Drag and Drop Content: QPixmap feedbackPixmap(qreal width, qreal height) override; bool needSpaceForFeedbackPixmap() override { return true; } // Open Content or File: QString messageWhenOpening(OpenMessage where) override; QString customOpenCommand() override; // Content-Specific Methods: void setPixmap(const QPixmap &pixmap); /// << Change the pixmap note-content and relayout the note. QPixmap pixmap() { return m_pixmapItem.pixmap(); } /// << @return the pixmap note-content. QByteArray data(); QGraphicsItem *graphicsItem() override { return &m_pixmapItem; } protected: QGraphicsPixmapItem m_pixmapItem; QByteArray m_format; }; /** Real implementation of animated image (GIF, MNG) notes: * @author Sébastien Laoût */ -class AnimationContent : public QObject, public NoteContent // QObject to be able to receive QMovie signals +class BASKET_EXPORT AnimationContent : public QObject, public NoteContent // QObject to be able to receive QMovie signals { Q_OBJECT public: // Constructor and destructor: AnimationContent(Note *parent, const QString &fileName, bool lazyLoad = false); ~AnimationContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; QPixmap toPixmap() override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; void fontChanged() override; QString editToolTipText() const override; // Drag and Drop Content: QPixmap feedbackPixmap(qreal width, qreal height) override; bool needSpaceForFeedbackPixmap() override { return true; } // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal width) override; bool loadFromFile(bool lazyLoad) override; bool finishLazyLoad() override; bool saveToFile() override; // Open Content or File: QString messageWhenOpening(OpenMessage where) override; QString customOpenCommand() override; QGraphicsItem *graphicsItem() override { return &m_graphicsPixmap; } // Content-Specific Methods: bool startMovie(); protected slots: void movieUpdated(); void movieResized(); void movieFrameChanged(); protected: QBuffer *m_buffer; QMovie *m_movie; qreal m_currentWidth; QGraphicsPixmapItem m_graphicsPixmap; }; /** Real implementation of file notes: * @author Sébastien Laoût */ -class FileContent : public QObject, public NoteContent +class BASKET_EXPORT FileContent : public QObject, public NoteContent { Q_OBJECT public: // Constructor and destructor: FileContent(Note *parent, const QString &fileName); ~FileContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal width) override; bool loadFromFile(bool /*lazyLoad*/) override; void fontChanged() override; void linkLookChanged() override; QString editToolTipText() const override; void toolTipInfos(QStringList *keys, QStringList *values) override; // Drag and Drop Content: QPixmap feedbackPixmap(qreal width, qreal height) override; // Custom Zones: int zoneAt(const QPointF &pos) override; QRectF zoneRect(int zone, const QPointF & /*pos*/) override; QString zoneTip(int zone) override; Qt::CursorShape cursorFromZone(int zone) const override; // Content Edition: int xEditorIndent() override; // Open Content or File: QString messageWhenOpening(OpenMessage where) override; // Content-Specific Methods: void setFileName(const QString &fileName) override; /// << Reimplemented to be able to relayout the note. virtual LinkLook *linkLook() { return LinkLook::fileLook; } QGraphicsItem *graphicsItem() override { return &m_linkDisplayItem; } protected: LinkDisplayItem m_linkDisplayItem; // File Preview Management: protected slots: void newPreview(const KFileItem &, const QPixmap &preview); void removePreview(const KFileItem &); void startFetchingUrlPreview(); protected: KIO::PreviewJob *m_previewJob; }; /** Real implementation of sound notes: * @author Sébastien Laoût */ -class SoundContent : public FileContent // A sound is a file with just a bit different user interaction +class BASKET_EXPORT SoundContent : public FileContent // A sound is a file with just a bit different user interaction { Q_OBJECT public: // Constructor and destructor: SoundContent(Note *parent, const QString &fileName); // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; QString editToolTipText() const override; // Complex Generic Methods: QString cssClass() const override; // Custom Zones: QString zoneTip(int zone) override; void setHoveredZone(int oldZone, int newZone) override; // Open Content or File: QString messageWhenOpening(OpenMessage where) override; QString customOpenCommand() override; // Content-Specific Methods: LinkLook *linkLook() override { return LinkLook::soundLook; } Phonon::MediaObject *music; private slots: void stateChanged(Phonon::State, Phonon::State); }; /** Real implementation of link notes: * @author Sébastien Laoût */ -class LinkContent : public QObject, public NoteContent +class BASKET_EXPORT LinkContent : public QObject, public NoteContent { Q_OBJECT public: // Constructor and destructor: LinkContent(Note *parent, const QUrl &url, const QString &title, const QString &icon, bool autoTitle, bool autoIcon); ~LinkContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toText(const QString & /*cuttedFullPath*/) override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; void toLink(QUrl *url, QString *title, const QString &cuttedFullPath) override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal width) override; void saveToNode(QXmlStreamWriter &stream) override; void fontChanged() override; void linkLookChanged() override; QString editToolTipText() const override; void toolTipInfos(QStringList *keys, QStringList *values) override; // Drag and Drop Content: void serialize(QDataStream &stream) override; QPixmap feedbackPixmap(qreal width, qreal height) override; // Custom Zones: int zoneAt(const QPointF &pos) override; QRectF zoneRect(int zone, const QPointF & /*pos*/) override; QString zoneTip(int zone) override; Qt::CursorShape cursorFromZone(int zone) const override; QString statusBarMessage(int zone) override; // Open Content or File: QUrl urlToOpen(bool /*with*/) override; QString messageWhenOpening(OpenMessage where) override; // Content-Specific Methods: void setLink(const QUrl &url, const QString &title, const QString &icon, bool autoTitle, bool autoIcon); /// << Change the link and relayout the note. QUrl url() { return m_url; } /// << @return the URL of the link note-content. QString title() { return m_title; } /// << @return the displayed title of the link note-content. QString icon() { return m_icon; } /// << @return the displayed icon of the link note-content. bool autoTitle() { return m_autoTitle; } /// << @return if the title is auto-computed from the URL. bool autoIcon() { return m_autoIcon; } /// << @return if the icon is auto-computed from the URL. void startFetchingLinkTitle(); QGraphicsItem *graphicsItem() override { return &m_linkDisplayItem; } protected: QUrl m_url; QString m_title; QString m_icon; bool m_autoTitle; bool m_autoIcon; LinkDisplayItem m_linkDisplayItem; KIO::Integration::AccessManager *m_access_manager; QNetworkReply *m_reply; QByteArray m_httpBuff; ///< Accumulator for downloaded HTTP data with yet unknown encoding bool m_acceptingData; ///< When false, don't accept any HTTP data // File Preview Management: protected slots: void httpReadyRead(); void httpDone(QNetworkReply *reply); void newPreview(const KFileItem &, const QPixmap &preview); void removePreview(const KFileItem &); void startFetchingUrlPreview(); protected: KIO::PreviewJob *m_previewJob; private: void decodeHtmlTitle(); ///< Detect encoding of \p m_httpBuff and extract the title from HTML void endFetchingLinkTitle(); ///< Extract title and clear http buffer }; /** Real implementation of cross reference notes: * Copied and modified from LinkContent. * @author Brian C. Milco */ -class CrossReferenceContent : public QObject, public NoteContent +class BASKET_EXPORT CrossReferenceContent : public QObject, public NoteContent { Q_OBJECT public: // Constructor and destructor: CrossReferenceContent(Note *parent, const QUrl &url, const QString &title, const QString &icon); ~CrossReferenceContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toText(const QString & /*cuttedFullPath*/) override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; void toLink(QUrl *url, QString *title, const QString &cuttedFullPath) override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal) override; void saveToNode(QXmlStreamWriter &stream) override; void fontChanged() override; void linkLookChanged() override; QString editToolTipText() const override; void toolTipInfos(QStringList *keys, QStringList *values) override; // Drag and Drop Content: void serialize(QDataStream &stream) override; QPixmap feedbackPixmap(qreal width, qreal height) override; // Custom Zones: int zoneAt(const QPointF &pos) override; QRectF zoneRect(int zone, const QPointF & /*pos*/) override; QString zoneTip(int zone) override; Qt::CursorShape cursorFromZone(int zone) const override; QString statusBarMessage(int zone) override; // Open Content or File: QUrl urlToOpen(bool /*with*/) override; QString messageWhenOpening(OpenMessage where) override; // Content-Specific Methods: void setLink(const QUrl &url, const QString &title, const QString &icon); /// << Change the link and relayout the note. void setCrossReference(const QUrl &url, const QString &title, const QString &icon); QUrl url() { return m_url; } /// << @return the URL of the link note-content. QString title() { return m_title; } /// << @return the displayed title of the link note-content. QString icon() { return m_icon; } /// << @return the displayed icon of the link note-content. QGraphicsItem *graphicsItem() override { return &m_linkDisplayItem; } protected: QUrl m_url; QString m_title; QString m_icon; LinkDisplayItem m_linkDisplayItem; }; /** Real implementation of launcher notes: * @author Sébastien Laoût */ -class LauncherContent : public NoteContent +class BASKET_EXPORT LauncherContent : public NoteContent { public: // Constructor and destructor: LauncherContent(Note *parent, const QString &fileName); ~LauncherContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; void toLink(QUrl *url, QString *title, const QString &cuttedFullPath) override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal width) override; bool loadFromFile(bool /*lazyLoad*/) override; void fontChanged() override; QString editToolTipText() const override; void toolTipInfos(QStringList *keys, QStringList *values) override; // Drag and Drop Content: QPixmap feedbackPixmap(qreal width, qreal height) override; // Custom Zones: int zoneAt(const QPointF &pos) override; QRectF zoneRect(int zone, const QPointF & /*pos*/) override; QString zoneTip(int zone) override; Qt::CursorShape cursorFromZone(int zone) const override; // Open Content or File: QUrl urlToOpen(bool with) override; QString messageWhenOpening(OpenMessage where) override; // Content-Specific Methods: void setLauncher(const QString &name, const QString &icon, const QString &exec); /// << Change the launcher note-content and relayout the note. Normally called by loadFromFile (no save done). QString name() { return m_name; } /// << @return the URL of the launcher note-content. QString icon() { return m_icon; } /// << @return the displayed icon of the launcher note-content. QString exec() { return m_exec; } /// << @return the execute command line of the launcher note-content. // TODO: KService *service() ??? And store everything in thta service ? QGraphicsItem *graphicsItem() override { return &m_linkDisplayItem; } protected: QString m_name; // TODO: Store them in linkDisplay to gain place (idem for Link notes) QString m_icon; QString m_exec; LinkDisplayItem m_linkDisplayItem; }; /** * */ -class ColorItem : public QGraphicsItem +class BASKET_EXPORT ColorItem : public QGraphicsItem { public: ColorItem(Note *parent, const QColor &color); // virtual ~ColorItem(); virtual QColor color() { return m_color; } virtual void setColor(const QColor &color); QRectF boundingRect() const override; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; private: Note *m_note; QColor m_color; QRectF m_textRect; static const int RECT_MARGIN; }; /** Real implementation of color notes: * @author Sébastien Laoût */ -class ColorContent : public NoteContent +class BASKET_EXPORT ColorContent : public NoteContent { public: // Constructor and destructor: ColorContent(Note *parent, const QColor &color); ~ColorContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toText(const QString & /*cuttedFullPath*/) override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal width) override; void saveToNode(QXmlStreamWriter &stream) override; void fontChanged() override; QString editToolTipText() const override; void toolTipInfos(QStringList *keys, QStringList *values) override; // Drag and Drop Content: void serialize(QDataStream &stream) override; QPixmap feedbackPixmap(qreal width, qreal height) override; bool needSpaceForFeedbackPixmap() override { return true; } void addAlternateDragObjects(QMimeData *dragObject) override; // Content-Specific Methods: void setColor(const QColor &color); /// << Change the color note-content and relayout the note. QColor color() { return m_colorItem.color(); } /// << @return the color note-content. QGraphicsItem *graphicsItem() override { return &m_colorItem; } protected: ColorItem m_colorItem; }; /** * */ -class UnknownItem : public QGraphicsItem +class BASKET_EXPORT UnknownItem : public QGraphicsItem { public: UnknownItem(Note *parent); QRectF boundingRect() const override; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; virtual QString mimeTypes() { return m_mimeTypes; } virtual void setMimeTypes(QString mimeTypes); virtual void setWidth(qreal width); private: Note *m_note; QString m_mimeTypes; QRectF m_textRect; static const qreal DECORATION_MARGIN; }; /** Real implementation of unknown MIME-types dropped notes: * @author Sébastien Laoût */ -class UnknownContent : public NoteContent +class BASKET_EXPORT UnknownContent : public NoteContent { public: // Constructor and destructor: UnknownContent(Note *parent, const QString &fileName); ~UnknownContent() override; // Simple Generic Methods: NoteType::Id type() const override; QString typeName() const override; QString lowerTypeName() const override; QString toText(const QString & /*cuttedFullPath*/) override; QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; void toLink(QUrl *url, QString *title, const QString &cuttedFullPath) override; bool useFile() const override; bool canBeSavedAs() const override; QString saveAsFilters() const override; bool match(const FilterData &data) override; // Complex Generic Methods: void exportToHTML(HTMLExporter *exporter, int indent) override; QString cssClass() const override; qreal setWidthAndGetHeight(qreal width) override; bool loadFromFile(bool /*lazyLoad*/) override; void fontChanged() override; QString editToolTipText() const override; // Drag and Drop Content: bool shouldSerializeFile() override { return false; } void addAlternateDragObjects(QMimeData *dragObject) override; QPixmap feedbackPixmap(qreal width, qreal height) override; bool needSpaceForFeedbackPixmap() override { return true; } // Open Content or File: QUrl urlToOpen(bool /*with*/) override { return QUrl(); } QGraphicsItem *graphicsItem() override { return &m_unknownItem; } // Content-Specific Methods: QString mimeTypes() { return m_unknownItem.mimeTypes(); } /// << @return the list of MIME types this note-content contains. private: UnknownItem m_unknownItem; }; #endif // NOTECONTENT_H diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 40d76aa..575b74b 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,47 +1,15 @@ -include(ECMMarkAsTest) - -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) - -find_package(Qt5Test REQUIRED) - -add_custom_target(tests) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src - ${CMAKE_BINARY_DIR}/src) - -link_directories(${CMAKE_BINARY_DIR}/lib) - - -macro(basket_standalone_unit_test _testname) - add_executable(${_testname} ${_testname}.cpp ${_extra_sources} ${ARGN}) - ecm_mark_as_test(${_testname}) - add_dependencies(tests ${_testname}) #include into "tests" build target - target_link_libraries(${_testname} basketcommon Qt5::Test) -endmacro(basket_standalone_unit_test) +########### next target ############### +include(ECMMarkAsTest) +include(ECMAddTests) -macro(basket_full_unit_test _testname) - include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${SOPRANO_INCLUDE_DIR}) - - #set(baskettest_SRCS " ") - foreach (cpp ${basketcommon_LIB_SRCS}) - set(IS_GENERATED (${cpp} MATCHES "(^/)")) # Generated files contain full path (start with '/') - if(${IS_GENERATED}) - # Not used now (included via basketcommon target) - #list(APPEND baskettest_SRCS ${cpp}) - else(${IS_GENERATED}) - list(APPEND baskettest_SRCS "${CMAKE_SOURCE_DIR}/src/${cpp}") - endif(${IS_GENERATED}) - endforeach () +find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test) - add_executable(${_testname} ${_testname}.cpp ${baskettest_SRCS}) - ecm_mark_as_test(${_testname}) - add_dependencies(tests ${_testname}) - - target_link_libraries(${_testname} basketcommon ${GPGME_VANILLA_LIBRARIES} Qt5::Test) -endmacro(basket_full_unit_test) +set(BASKET_TEST_SRC + notetest.cpp + basketviewtest.cpp + toolstest.cpp +) +ecm_add_tests(${BASKET_TEST_SRC} LINK_LIBRARIES LibBasket Qt5::Test) -basket_standalone_unit_test(notetest) -basket_standalone_unit_test(basketviewtest) -basket_full_unit_test(toolstest) diff --git a/src/tests/basketviewtest.cpp b/src/tests/basketviewtest.cpp index 791b2e6..24a7954 100644 --- a/src/tests/basketviewtest.cpp +++ b/src/tests/basketviewtest.cpp @@ -1,25 +1,26 @@ /** * SPDX-FileCopyrightText: (C) 2009 Matt Rogers + * * SPDX-License-Identifier: GPL-2.0-or-later */ #include #include -#include "basketview.h" -#include "note.h" +#include +#include class BasketViewTest : public QObject { Q_OBJECT private Q_SLOTS: void testCreation(); }; QTEST_MAIN(BasketViewTest) void BasketViewTest::testCreation() { } #include "basketviewtest.moc" /* vim: set et sts=4 sw=4 ts=8 tw=0 : */ diff --git a/src/tests/notetest.cpp b/src/tests/notetest.cpp index 4c3b655..52b6d86 100644 --- a/src/tests/notetest.cpp +++ b/src/tests/notetest.cpp @@ -1,36 +1,36 @@ /** * SPDX-FileCopyrightText: (C) 2009 Matt Rogers * SPDX-License-Identifier: GPL-2.0-or-later */ #include #include -#include "basketview.h" -#include "note.h" +#include +#include class NoteTest : public QObject { Q_OBJECT private Q_SLOTS: void testCreation(); }; QTEST_MAIN(NoteTest) void NoteTest::testCreation() { Note *n = new Note(nullptr); QVERIFY(n->basket() == nullptr); QVERIFY(n->next() == nullptr); QVERIFY(n->prev() == nullptr); QVERIFY(n->content() == nullptr); QCOMPARE(n->x(), 0.0); QCOMPARE(n->y(), 0.0); QCOMPARE(n->width(), Note::GROUP_WIDTH); QCOMPARE(n->height(), Note::MIN_HEIGHT); delete n; } #include "notetest.moc" /* vim: set et sts=4 sw=4 ts=8 tw=0 : */ diff --git a/src/tests/toolstest.cpp b/src/tests/toolstest.cpp index abbe5a4..f1f2b6e 100644 --- a/src/tests/toolstest.cpp +++ b/src/tests/toolstest.cpp @@ -1,50 +1,50 @@ /** * SPDX-FileCopyrightText: (C) 2014 Gleb Baryshev * SPDX-License-Identifier: GPL-2.0-or-later */ #include #include -#include "tools.h" +#include class ToolsTest : public QObject { Q_OBJECT private Q_SLOTS: void testHtmlToText(); private: bool readAll(QString fileName, QString &text); }; QTEST_MAIN(ToolsTest) void ToolsTest::testHtmlToText() { // Test the function on files from htmltotext/ for (int i = 1; i <= 5; i++) { QString html, text; QString basename = QFINDTESTDATA("htmltotext/"); QVERIFY2(QDir(basename).exists(), "Test data file not found"); basename += QString::number(i); if (readAll(basename + ".html", html) && readAll(basename + ".txt", text)) QCOMPARE(Tools::htmlToText(html), text); } } bool ToolsTest::readAll(QString fileName, QString &text) { QFile f(fileName); if (!f.open(QFile::ReadOnly | QFile::Text)) { QWARN(QString("Failed to open data file %1 - skipping").arg(fileName).toUtf8()); return false; } QTextStream filestream(&f); text = filestream.readAll(); return true; } #include "toolstest.moc" diff --git a/src/tools.h b/src/tools.h index 27188a0..298cc23 100644 --- a/src/tools.h +++ b/src/tools.h @@ -1,117 +1,119 @@ /** * SPDX-FileCopyrightText: (C) 2003 Sébastien Laoût * * SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef TOOLS_H #define TOOLS_H +#include "basket_export.h" + #include class QColor; class QFont; class QMimeData; class QObject; class QPixmap; class QString; class QStringList; class QTime; class QTextDocument; class HTMLExporter; class StopWatch { public: static void start(int id); static void check(int id); private: static QVector starts; static QVector totals; static QVector counts; }; /** Some useful functions for that application. * @author Sébastien Laoût */ -namespace Tools +namespace BASKET_EXPORT Tools { // Text <-> HTML Conversions and Tools: QString textToHTML(const QString &text); QString textToHTMLWithoutP(const QString &text); QString htmlToParagraph(const QString &html); QString htmlToText(const QString &html); QString textDocumentToMinimalHTML(QTextDocument *document); //!< Avoid unneeded spans and style attributes QString tagURLs(const QString &test); QString cssFontDefinition(const QFont &font, bool onlyFontFamily = false); // Cross Reference tools: QString tagCrossReferences(const QString &text, bool userLink = false, HTMLExporter *exporter = nullptr); // private functions: QString crossReferenceForBasket(QStringList linkParts); QString crossReferenceForHtml(QStringList linkParts, HTMLExporter *exporter); QString crossReferenceForConversion(QStringList linkParts); // String Manipulations: QString stripEndWhiteSpaces(const QString &string); QString makeStandardCaption(const QString &userCaption); //!< Replacement for KDialog::makeStandardCaption // Pixmap Manipulations: /** @Return the CSS color name for the given @p colorHex in #rrggbb format, or empty string if none matches */ QString cssColorName(const QString &colorHex); /** @Return true if it is a Web color */ bool isWebColor(const QColor &color); /** @Return a color that is 50% of @p color1 and 50% of @p color2. */ QColor mixColor(const QColor &color1, const QColor &color2, const float ratio = 1); /** @Return true if the color is too dark to be darkened one more time. */ bool tooDark(const QColor &color); /** Make sure the @p pixmap is of the size (@p width, @p height) and @return a pixmap of this size. * If @p height <= 0, then width will be used to make the picture square. */ QPixmap normalizePixmap(const QPixmap &pixmap, int width, int height = 0); /** @Return the pixmap @p source with depth*deltaX transparent pixels added to the left.\n * If @p deltaX is <= 0, then an indent delta is computed depending on the @p source width. */ QPixmap indentPixmap(const QPixmap &source, int depth, int deltaX = 0); // File and Folder Manipulations: /** Delete the folder @p folderOrFile recursively (to remove sub-folders and child files too). */ void deleteRecursively(const QString &folderOrFile); /** Trash the folder @p folderOrFile recursively (to move sub-folders and child files to the Trash, too). */ void trashRecursively(const QString &folderOrFile); /** Delete the metadata of file or folder @p folderOrFile from Nepomuk, recursively. */ void deleteMetadataRecursively(const QString &folderOrFile); /** @Return a new filename that doesn't already exist in @p destFolder. * If @p wantedName already exist in @p destFolder, a dash and a number will be added before the extension. * Id there were already such a number in @p wantedName, it is incremented until a free filename is found. */ QString fileNameForNewFile(const QString &wantedName, const QString &destFolder); //! @returns Total size in bytes of all files and subdirectories qint64 computeSizeRecursively(const QString &path); // Other: // void iconForURL(const QUrl &url); /** @Return true if the source is from a file cutting in Konqueror. * @Return false if it was just a copy or if it was a drag. */ bool isAFileCut(const QMimeData *source); /// Implementation of system encoding detection from KDE 4 QByteArray systemCodeset(); // Debug void printChildren(QObject *parent); } #endif // TOOLS_H