diff --git a/kcms/access/CMakeLists.txt b/kcms/access/CMakeLists.txt index 4f48d3961..207b575dd 100644 --- a/kcms/access/CMakeLists.txt +++ b/kcms/access/CMakeLists.txt @@ -1,28 +1,27 @@ # KI18N Translation Domain for this library add_definitions(-DTRANSLATION_DOMAIN=\"kcmaccess\") set(kcm_access_PART_SRCS kcmaccess.cpp ) ki18n_wrap_ui(kcm_access_PART_SRCS accessibility.ui ) add_library(kcm_access MODULE ${kcm_access_PART_SRCS}) target_link_libraries(kcm_access Qt5::X11Extras KF5::KCMUtils KF5::I18n KF5::KIOCore KF5::KIOWidgets KF5::NotifyConfig KF5::WindowSystem - KF5::KDELibs4Support ${X11_LIBRARIES} ) install(TARGETS kcm_access DESTINATION ${KDE_INSTALL_PLUGINDIR}) ########### install files ############### install( FILES kcmaccess.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) diff --git a/kcms/keyboard/flags.cpp b/kcms/keyboard/flags.cpp index 7fc7eb70f..6b363f9d9 100644 --- a/kcms/keyboard/flags.cpp +++ b/kcms/keyboard/flags.cpp @@ -1,297 +1,296 @@ /* * Copyright (C) 2010 Andriy Rysin (rysin@kde.org) * * 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. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "flags.h" -#include #include #include #include #include #include #include #include #include #include #include #include #include "x11_helper.h" //for text handling #include "keyboard_config.h" #include "xkb_rules.h" static const int FLAG_MAX_SIZE = 22; static const char flagTemplate[] = "kf5/locale/countries/%1/flag.png"; int iconSize(int s) { if (s < 16) { return 16; } else if (s < 22) { return 22; } else if (s < 32) { return 32; } else if (s < 48) { return 48; } else if (s < 64) { return 64; } else { return 128; } } Flags::Flags(): svg(nullptr) { transparentPixmap = new QPixmap(FLAG_MAX_SIZE, FLAG_MAX_SIZE); transparentPixmap->fill(Qt::transparent); } Flags::~Flags() { if( svg != nullptr ) { disconnect(svg, &Plasma::Svg::repaintNeeded, this, &Flags::themeChanged); delete svg; } delete transparentPixmap; } const QIcon Flags::getIcon(const QString& layout) { if( ! iconMap.contains(layout) ) { iconMap[ layout ] = createIcon(layout); } return iconMap[ layout ]; } QIcon Flags::createIcon(const QString& layout) { QIcon icon; if( ! layout.isEmpty() ) { QString file; if( layout == QLatin1String("epo") ) { file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kcmkeyboard/pics/epo.png")); } else { QString countryCode = getCountryFromLayoutName( layout ); if( ! countryCode.isEmpty() ) { file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString(flagTemplate).arg(countryCode)); // qCDebug(KCM_KEYBOARD, ) << "Creating icon for" << layout << "with" << file; } } if (!file.isEmpty()) { QImage flagImg; flagImg.load(file); const int size = iconSize(qMax(flagImg.width(), flagImg.height())); QPixmap iconPix(size, size); iconPix.fill(Qt::transparent); QRect dest(flagImg.rect()); dest.moveCenter(iconPix.rect().center()); QPainter painter(&iconPix); painter.drawImage(dest, flagImg); painter.end(); icon.addPixmap(iconPix); } } return icon; } //static //const QStringList NON_COUNTRY_LAYOUTS = QString("ara,brai,epo,latam,mao").split(","); QString Flags::getCountryFromLayoutName(const QString& layout) const { QString countryCode = layout; if( countryCode == QLatin1String("nec_vndr/jp") ) return QStringLiteral("jp"); // if( NON_COUNTRY_LAYOUTS.contain(layout) ) if( countryCode.length() > 2 ) return QLatin1String(""); return countryCode; } //TODO: move this to some other class? QString Flags::getShortText(const LayoutUnit& layoutUnit, const KeyboardConfig& keyboardConfig) { if( layoutUnit.isEmpty() ) return QStringLiteral("--"); QString layoutText = layoutUnit.layout; foreach(const LayoutUnit& lu, keyboardConfig.layouts) { if( layoutUnit.layout == lu.layout && layoutUnit.variant == lu.variant ) { layoutText = lu.getDisplayName(); break; } } //TODO: good autolabel // if( layoutText == layoutUnit.layout && layoutUnit.getDisplayName() != layoutUnit.layout ) { // layoutText = layoutUnit.getDisplayName(); // } return layoutText; } QString Flags::getFullText(const LayoutUnit& layoutUnit, const KeyboardConfig& keyboardConfig, const Rules* rules) { QString shortText = Flags::getShortText(layoutUnit, keyboardConfig); QString longText = Flags::getLongText(layoutUnit, rules); return i18nc("short layout label - full layout name", "%1 - %2", shortText, longText); } static QString getDisplayText(const QString& layout, const QString& variant, const Rules* rules) { if( variant.isEmpty() ) return layout; if( rules == nullptr || rules->version == QLatin1String("1.0") ) return i18nc("layout - variant", "%1 - %2", layout, variant); return variant; } QString Flags::getLongText(const LayoutUnit& layoutUnit, const Rules* rules) { if( rules == nullptr ) { return getDisplayText(layoutUnit.layout, layoutUnit.variant, rules); } QString layoutText = layoutUnit.layout; const LayoutInfo* layoutInfo = rules->getLayoutInfo(layoutUnit.layout); if( layoutInfo != nullptr ) { layoutText = layoutInfo->description; if( ! layoutUnit.variant.isEmpty() ) { const VariantInfo* variantInfo = layoutInfo->getVariantInfo(layoutUnit.variant); QString variantText = variantInfo != nullptr ? variantInfo->description : layoutUnit.variant; layoutText = getDisplayText(layoutText, variantText, rules); } } return layoutText; } static QString getPixmapKey(const KeyboardConfig& keyboardConfig) { switch(keyboardConfig.indicatorType) { case KeyboardConfig::SHOW_FLAG: return QStringLiteral("_fl"); case KeyboardConfig::SHOW_LABEL_ON_FLAG: return QStringLiteral("_bt"); case KeyboardConfig::SHOW_LABEL: return QStringLiteral("_lb"); } return QStringLiteral("_"); // should not happen } void Flags::drawLabel(QPainter& painter, const QString& layoutText, bool flagShown) { QFont font = painter.font(); QRect rect = painter.window(); font.setPointSize(KFontUtils::adaptFontSize(painter, layoutText, rect.size(), rect.height())); // we init svg so that we get notification about theme change getSvg(); const QColor textColor = flagShown ? Qt::black : Plasma::Theme().color(Plasma::Theme::TextColor); painter.setPen(textColor); painter.setFont(font); painter.drawText(rect, Qt::AlignCenter, layoutText); } const QIcon Flags::getIconWithText(const LayoutUnit& layoutUnit, const KeyboardConfig& keyboardConfig) { const QString keySuffix(getPixmapKey(keyboardConfig)); const QString key(layoutUnit.toString() + keySuffix); if( iconOrTextMap.contains(key) ) { return iconOrTextMap[ key ]; } if( keyboardConfig.indicatorType == KeyboardConfig::SHOW_FLAG ) { QIcon icon = getIcon(layoutUnit.layout); if( ! icon.isNull() ) { iconOrTextMap[ key ] = icon; return icon; } } QString layoutText = Flags::getShortText(layoutUnit, keyboardConfig); const QSize TRAY_ICON_SIZE(128, 128); QPixmap pixmap = QPixmap(TRAY_ICON_SIZE); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); painter.setRenderHint(QPainter::SmoothPixmapTransform); // p.setRenderHint(QPainter::Antialiasing); if( keyboardConfig.indicatorType == KeyboardConfig::SHOW_LABEL_ON_FLAG ) { QIcon iconf = createIcon(layoutUnit.layout); painter.drawPixmap(pixmap.rect(), iconf.pixmap(TRAY_ICON_SIZE)); } drawLabel(painter, layoutText, keyboardConfig.isFlagShown()); painter.end(); QIcon icon(pixmap); iconOrTextMap[ key ] = icon; return icon; } Plasma::Svg* Flags::getSvg() { if( svg == nullptr ) { svg = new Plasma::Svg; svg->setImagePath(QStringLiteral("widgets/labeltexture")); svg->setContainsMultipleImages(true); connect(svg, &Plasma::Svg::repaintNeeded, this, &Flags::themeChanged); } return svg; } void Flags::themeChanged() { // qCDebug(KCM_KEYBOARD, ) << "Theme changed, new text color" << Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); clearCache(); emit pixmapChanged(); } void Flags::clearCache() { // qCDebug(KCM_KEYBOARD, ) << "Clearing flag pixmap cache"; iconOrTextMap.clear(); } diff --git a/kcms/keyboard/tests/CMakeLists.txt b/kcms/keyboard/tests/CMakeLists.txt index 1e8842ea3..e5318c5aa 100644 --- a/kcms/keyboard/tests/CMakeLists.txt +++ b/kcms/keyboard/tests/CMakeLists.txt @@ -1,107 +1,113 @@ macro(KEYBOARD_DAEMON_UNIT_TESTS _testname) add_executable(${_testname}_test ${_testname}_test.cpp ../${_testname}.cpp ../debug.cpp) ecm_mark_nongui_executable(${_testname}_test) ecm_mark_as_test(${_testname}_test) add_test(NAME kcm-keyboard-${_testname} COMMAND ${_testname}_test) target_link_libraries(${_testname}_test Qt5::Concurrent Qt5::Widgets Qt5::X11Extras Qt5::Xml Qt5::Test KF5::I18n - KF5::KDELibs4Support + KF5::WindowSystem ${X11_Xkbfile_LIB} ${X11_LIBRARIES} ) endmacro(KEYBOARD_DAEMON_UNIT_TESTS) macro(KEYBOARD_PREVIEW_UNIT_TESTS _testname) include_directories("..") set(test_SRCS ../preview/${_testname}.cpp ../preview/geometry_components.cpp ../xkb_rules.cpp ../debug.cpp) add_executable(${_testname}_test ${_testname}_test.cpp ${test_SRCS}) ecm_mark_nongui_executable(${_testname}_test) ecm_mark_as_test(${_testname}_test) add_test(NAME kcm-keyboard-${_testname} COMMAND ${_testname}_test) target_link_libraries(${_testname}_test Qt5::Concurrent Qt5::Widgets Qt5::X11Extras Qt5::Xml Qt5::Test KF5::I18n - KF5::KDELibs4Support + KF5::WindowSystem ${X11_Xkbfile_LIB} ${X11_LIBRARIES} ) set_source_files_properties(${test_SRCS} PROPERTIES COMPILE_FLAGS "-fexceptions") endmacro(KEYBOARD_PREVIEW_UNIT_TESTS) keyboard_daemon_unit_tests(xkb_rules) keyboard_daemon_unit_tests(iso_codes) find_package(Boost) if(Boost_FOUND) keyboard_preview_unit_tests(geometry_parser) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # the default maximum template expansion depth (256) is not enough set_property(SOURCE ../preview/geometry_parser.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -ftemplate-depth=512") endif() # set_source_files_properties(${preview_SRCS} PROPERTIES COMPILE_FLAGS "-fexceptions") endif(Boost_FOUND) add_executable(flags_test flags_test.cpp ../flags.cpp ../x11_helper.cpp ../keyboard_config.cpp ../xkb_rules.cpp ../debug.cpp) ecm_mark_nongui_executable(flags_test) ecm_mark_as_test(flags_test) add_test(NAME kcm-keyboard-flags_test COMMAND flags_test) target_link_libraries(flags_test Qt5::Concurrent Qt5::X11Extras Qt5::Xml Qt5::Test + Qt5::Widgets + KF5::GuiAddons KF5::I18n KF5::Plasma - KF5::KDELibs4Support + KF5::WindowSystem XCB::XCB XCB::XKB ${X11_Xkbfile_LIB} ${X11_LIBRARIES} ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config/base.1.1.xml ${CMAKE_CURRENT_BINARY_DIR}/config/base.1.1.xml COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config/base.bad.xml ${CMAKE_CURRENT_BINARY_DIR}/config/base.bad.xml COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config/base.xml ${CMAKE_CURRENT_BINARY_DIR}/config/base.xml COPYONLY) if( X11_XTest_FOUND ) add_executable(keyboard_daemon_test keyboard_daemon_test.cpp ../keyboard_daemon.cpp ../layout_memory.cpp ../layout_memory_persister.cpp ../flags.cpp ../udev_helper.cpp ../x11_helper.cpp ../xkb_helper.cpp ../xinput_helper.cpp ../layout_tray_icon.cpp ../keyboard_config.cpp ../xkb_rules.cpp ../keyboard_hardware.cpp ../bindings.cpp ../layouts_menu.cpp ../debug.cpp) add_test(NAME kcm-keyboard-keyboard_daemon_test COMMAND keyboard_daemon_test) add_dependencies(keyboard_daemon_test kded_keyboard) ecm_mark_nongui_executable(keyboard_daemon_test) ecm_mark_as_test(keyboard_daemon_test) target_link_libraries(keyboard_daemon_test Qt5::Concurrent Qt5::X11Extras Qt5::Xml Qt5::Test KF5::ConfigCore KF5::CoreAddons KF5::DBusAddons + KF5::GuiAddons + KF5::I18n + KF5::Notifications KF5::Plasma - KF5::KDELibs4Support KF5::GlobalAccel + KF5::WindowSystem + KF5::XmlGui XCB::XCB XCB::XKB ${X11_Xkbfile_LIB} ${X11_XTest_LIB} ${X11_LIBRARIES} ) if (HAVE_XINPUT) target_link_libraries(keyboard_daemon_test ${X11_Xinput_LIB}) endif() if (HAVE_UDEV) target_link_libraries(keyboard_daemon_test ${UDEV_LIBS}) endif() endif() diff --git a/kcms/spellchecking/CMakeLists.txt b/kcms/spellchecking/CMakeLists.txt index 70ad18946..89b6cc8f2 100644 --- a/kcms/spellchecking/CMakeLists.txt +++ b/kcms/spellchecking/CMakeLists.txt @@ -1,13 +1,13 @@ set(kcm_spellchecking_SRCS spellchecking.cpp ) add_library(kcmspellchecking MODULE ${kcm_spellchecking_SRCS}) target_link_libraries(kcmspellchecking + KF5::ConfigWidgets KF5::SonnetUi - KF5::KDELibs4Support ) install(TARGETS kcmspellchecking DESTINATION ${KDE_INSTALL_PLUGINDIR} ) install( FILES spellchecking.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )