kde-workspace/plasma/applets/keyboard/keyboard.cpp

238 lines
7.9 KiB
C++
Raw Normal View History

generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
/* This file is part of the KDE project
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "keyboard.h"
#include <QVBoxLayout>
#include <Plasma/Svg>
#include <Plasma/PaintUtils>
#include <Plasma/ToolTipManager>
#include <KIcon>
#include <KStandardDirs>
#include <KDebug>
KeyboardApplet::KeyboardApplet(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args),
m_keyboardlayout(nullptr),
m_showflag(false),
m_showtext(true),
m_indicatorbox(nullptr),
m_spacer(nullptr)
{
KGlobal::locale()->insertCatalog("plasma_applet_keyboard");
setAspectRatioMode(Plasma::AspectRatioMode::IgnoreAspectRatio);
setHasConfigurationInterface(true);
setStatus(Plasma::ItemStatus::PassiveStatus);
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
m_keyboardlayout = new KKeyboardLayout(this);
connect(
m_keyboardlayout, SIGNAL(layoutChanged()),
this, SLOT(slotLayoutChanged())
);
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
}
void KeyboardApplet::init()
{
KConfigGroup configgroup = config();
m_showflag = configgroup.readEntry("showFlag", false);
m_showtext = configgroup.readEntry("showText", true);
setGlobalShortcut(KShortcut(Qt::ALT+Qt::CTRL+Qt::Key_K));
connect(
this, SIGNAL(activate()),
this, SLOT(slotNextLayout())
);
}
void KeyboardApplet::paintInterface(QPainter *painter,
const QStyleOptionGraphicsItem *option,
const QRect &contentsRect)
{
const KKeyboardType activelayout = m_keyboardlayout->layouts().first();
const QString layoutlayout = QString::fromLatin1(activelayout.layout.constData(), activelayout.layout.size());
if (m_showflag && m_flagpath.isEmpty()) {
m_flagpath = KStandardDirs::locate(
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
"locale",
QString::fromLatin1("l10n/%1/flag.png").arg(layoutlayout)
);
}
QFont font = KGlobalSettings::smallestReadableFont();
font.setBold(true);
font.setPointSize(qMax(font.pointSize(), contentsRect.height() / 2));
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
painter->setRenderHint(QPainter::SmoothPixmapTransform);
painter->setRenderHint(QPainter::Antialiasing);
const bool paintflag = (m_showflag && !m_flagpath.isEmpty());
if (paintflag) {
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
painter->save();
painter->drawPixmap(
contentsRect,
QPixmap(m_flagpath).scaled(contentsRect.size(), Qt::KeepAspectRatio)
);
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
painter->restore();
}
if (m_showtext) {
if (paintflag) {
painter->drawPixmap(
contentsRect,
Plasma::PaintUtils::shadowText(layoutlayout, font, Qt::black, Qt::white, QPoint(), 3)
);
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
} else {
Plasma::Svg* svg = new Plasma::Svg(this);
svg->setImagePath("widgets/labeltexture");
svg->setContainsMultipleImages(true);
painter->drawPixmap(
contentsRect,
Plasma::PaintUtils::texturedText(layoutlayout, font, svg)
);
delete svg;
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
}
}
}
void KeyboardApplet::createConfigurationInterface(KConfigDialog *parent)
{
QWidget* widget = new QWidget();
QVBoxLayout* widgetlayout = new QVBoxLayout(widget);
m_indicatorbox = new QComboBox(widget);
m_indicatorbox->addItem(i18n("Show text"));
m_indicatorbox->addItem(i18n("Show flag"));
m_indicatorbox->addItem(i18n("Show text and flag"));
if (m_showflag && m_showtext) {
m_indicatorbox->setCurrentIndex(2);
} else if (m_showflag) {
m_indicatorbox->setCurrentIndex(1);
} else {
m_indicatorbox->setCurrentIndex(0);
}
widgetlayout->addWidget(m_indicatorbox);
m_spacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding);
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
widgetlayout->addSpacerItem(m_spacer);
widget->setLayout(widgetlayout);
parent->addPage(widget, i18n("Indicator"), "applications-graphics");
connect(parent, SIGNAL(applyClicked()), this, SLOT(slotConfigAccepted()));
connect(parent, SIGNAL(okClicked()), this, SLOT(slotConfigAccepted()));
connect(m_indicatorbox, SIGNAL(currentIndexChanged(int)), parent, SLOT(settingsModified()));
}
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
void KeyboardApplet::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
slotNextLayout();
event->accept();
return;
}
event->ignore();
}
void KeyboardApplet::wheelEvent(QGraphicsSceneWheelEvent *event)
{
if (event->delta() < 0) {
slotNextLayout();
} else {
slotPreviousLayout();
}
}
void KeyboardApplet::constraintsEvent(Plasma::Constraints constraints)
{
if (constraints & Plasma::FormFactorConstraint) {
int iconsize = 0;
switch (formFactor()) {
case Plasma::FormFactor::Planar:
case Plasma::FormFactor::MediaCenter:
case Plasma::FormFactor::Application: {
// desktop-like
iconsize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
break;
}
case Plasma::FormFactor::Horizontal:
case Plasma::FormFactor::Vertical: {
// panel
iconsize = KIconLoader::global()->currentSize(KIconLoader::Panel);
break;
}
}
setMinimumSize(iconsize, iconsize);
}
}
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
void KeyboardApplet::slotLayoutChanged()
{
const QList<KKeyboardType> layouts = m_keyboardlayout->layouts();
const KKeyboardType activelayout = layouts.first();
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
const QString layoutlayout = QString::fromLatin1(activelayout.layout.constData(), activelayout.layout.size());
m_flagpath = KStandardDirs::locate(
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
"locale",
QString::fromLatin1("l10n/%1/flag.png").arg(layoutlayout)
);
QString layouttooltip;
layouttooltip.append(i18n("Model: %1<br/>", KKeyboardLayout::modelDescription(activelayout.model)));
layouttooltip.append(i18n("Variant: %1", KKeyboardLayout::variantDescription(activelayout.layout, activelayout.variant)));
Plasma::ToolTipContent plasmatooltipcontent = Plasma::ToolTipContent(
KKeyboardLayout::layoutDescription(activelayout.layout), layouttooltip,
KIcon(m_flagpath)
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
);
Plasma::ToolTipManager::self()->setContent(this, plasmatooltipcontent);
if (layouts.size() > 1) {
setStatus(Plasma::ItemStatus::ActiveStatus);
} else {
setStatus(Plasma::ItemStatus::PassiveStatus);
}
generic: keyboard layout applet and kayboard KCM reimplementation lots of changes with this commit - on the plasma applet side: + the applet now handles mouse wheel events * the applet itself sets its global global shortcut key + the applet itself has configuration interface for the text and flag options * ported to the new KKeyboardLayout class - no per-window or per-application keyboard layout on the overall keyboard configuration: * no KDED module required + keyboard layout descriptions (model, layout, variant, etc.) are actually translated - no keyboard configuration will be shown when a keyboard is plugged-in (see bellow) - keyboard layout options are not configurable, not via GUI interface anyway the hotplug plasma data engine, device notifications and solid actions have to be either reimplemented or extended to handle more device types (currently the above mentioned handle only removable devices by default such as cameras, not input devices such as keyboard) overall - from reimplemented one thing to another and the keyboard configuration is not done yet (adding and editing keyboard layout not implemented yet) but in a working state on a side note the changes here affect kvkbd as it uses D-Bus interface for keyboard layout change that is no more and has to be ported or (most likely) replaced with a handler for QEvent::RequestSoftwareInputPanel event that shows a keyboard on demand there is also the double-keyboard layout applet thing - applet for the keyboard layout could be added and the daemon (KDED module) was showing its own keyboard layout indicator automatically (by default) the X11 keyboard bell options are next to useless btw - there is KNotification::beep() for such things so the X11 bell options are simply dropped Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2023-09-03 21:48:19 +03:00
update();
}
void KeyboardApplet::slotNextLayout()
{
QList<KKeyboardType> layouts = m_keyboardlayout->layouts();
if (layouts.size() > 1) {
layouts.move(0, layouts.size() - 1);
m_keyboardlayout->setLayouts(layouts);
}
}
void KeyboardApplet::slotPreviousLayout()
{
QList<KKeyboardType> layouts = m_keyboardlayout->layouts();
if (layouts.size() > 1) {
layouts.move(layouts.size() - 1, 0);
m_keyboardlayout->setLayouts(layouts);
}
}
void KeyboardApplet::slotConfigAccepted()
{
Q_ASSERT(m_indicatorbox);
const int iconindex = m_indicatorbox->currentIndex();
m_showflag = (iconindex == 1 || iconindex == 2);
m_showtext = (iconindex == 0 || iconindex == 2);
KConfigGroup configgroup = config();
configgroup.writeEntry("showFlag", m_showflag);
configgroup.writeEntry("showText", m_showtext);
emit configNeedsSaving();
update();
}
#include "moc_keyboard.cpp"