diff options
Diffstat (limited to 'raveos-calamares-module/welcome')
| -rw-r--r-- | raveos-calamares-module/welcome/CMakeLists.txt | 9 | ||||
| -rw-r--r-- | raveos-calamares-module/welcome/RaveBillentyuzet.cpp | 81 | ||||
| -rw-r--r-- | raveos-calamares-module/welcome/RaveBillentyuzet.h | 16 | ||||
| -rw-r--r-- | raveos-calamares-module/welcome/RaveWelcomeViewStep.cpp | 191 | ||||
| -rw-r--r-- | raveos-calamares-module/welcome/RaveWelcomeViewStep.h | 14 | ||||
| -rw-r--r-- | raveos-calamares-module/welcome/ravewelcome.conf | 7 |
6 files changed, 264 insertions, 54 deletions
diff --git a/raveos-calamares-module/welcome/CMakeLists.txt b/raveos-calamares-module/welcome/CMakeLists.txt index 9d28587..063f23b 100644 --- a/raveos-calamares-module/welcome/CMakeLists.txt +++ b/raveos-calamares-module/welcome/CMakeLists.txt @@ -1,17 +1,22 @@ -find_package(Qt6 REQUIRED COMPONENTS Core Widgets) +find_package(Qt6 REQUIRED COMPONENTS Core Widgets Qml) +find_package(PkgConfig REQUIRED) +pkg_check_modules(XKBCOMMON REQUIRED IMPORTED_TARGET xkbcommon) calamares_add_plugin(ravewelcome TYPE viewmodule EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES RaveWelcomeViewStep.cpp + RaveBillentyuzet.cpp LINK_LIBRARIES Qt6::Core Qt6::Widgets + Qt6::Qml + PkgConfig::XKBCOMMON Calamares::calamares ) install( - FILES module.desc ravewelcome.conf + FILES module.desc DESTINATION lib/calamares/modules/ravewelcome ) diff --git a/raveos-calamares-module/welcome/RaveBillentyuzet.cpp b/raveos-calamares-module/welcome/RaveBillentyuzet.cpp new file mode 100644 index 0000000..aeb1205 --- /dev/null +++ b/raveos-calamares-module/welcome/RaveBillentyuzet.cpp @@ -0,0 +1,81 @@ +#include "RaveBillentyuzet.h" + +#include <QQmlEngine> + +#include <xkbcommon/xkbcommon.h> + +namespace +{ +constexpr int EvdevEltolas = 8; + +const QList< QList< int > >& sorKodok() +{ + static const QList< QList< int > > kodok { + { 41, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, + { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 }, + { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 43 }, + { 86, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 }, + }; + return kodok; +} +} + +QVariantList +RaveBillentyuzet::gombok( const QString& layout, const QString& variant ) const +{ + QVariantList sorok; + if ( layout.isEmpty() ) + { + return sorok; + } + + xkb_context* context = xkb_context_new( XKB_CONTEXT_NO_FLAGS ); + if ( !context ) + { + return sorok; + } + + const QByteArray layoutBytes = layout.toUtf8(); + const QByteArray variantBytes = variant.toUtf8(); + xkb_rule_names names {}; + names.rules = "evdev"; + names.model = "pc105"; + names.layout = layoutBytes.constData(); + names.variant = variantBytes.isEmpty() ? nullptr : variantBytes.constData(); + + xkb_keymap* keymap = xkb_keymap_new_from_names( context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS ); + if ( !keymap ) + { + xkb_context_unref( context ); + return sorok; + } + xkb_state* state = xkb_state_new( keymap ); + + for ( const auto& sor : sorKodok() ) + { + QVariantList cimkek; + for ( int kod : sor ) + { + char buffer[ 16 ] = {}; + xkb_state_key_get_utf8( state, static_cast< xkb_keycode_t >( kod + EvdevEltolas ), buffer, sizeof( buffer ) ); + cimkek << QString::fromUtf8( buffer ).toUpper(); + } + sorok << QVariant( cimkek ); + } + + xkb_state_unref( state ); + xkb_keymap_unref( keymap ); + xkb_context_unref( context ); + return sorok; +} + +void +RaveBillentyuzet::regisztral() +{ + if ( qmlTypeId( "RaveOSNative", 1, 0, "Billentyuzet" ) >= 0 ) + { + return; + } + qmlRegisterSingletonType< RaveBillentyuzet >( + "RaveOSNative", 1, 0, "Billentyuzet", []( QQmlEngine*, QJSEngine* ) -> QObject* { return new RaveBillentyuzet; } ); +} diff --git a/raveos-calamares-module/welcome/RaveBillentyuzet.h b/raveos-calamares-module/welcome/RaveBillentyuzet.h new file mode 100644 index 0000000..4a6b662 --- /dev/null +++ b/raveos-calamares-module/welcome/RaveBillentyuzet.h @@ -0,0 +1,16 @@ +#pragma once + +#include <QObject> +#include <QVariantList> + +class RaveBillentyuzet : public QObject +{ + Q_OBJECT + +public: + using QObject::QObject; + + Q_INVOKABLE QVariantList gombok( const QString& layout, const QString& variant ) const; + + static void regisztral(); +}; diff --git a/raveos-calamares-module/welcome/RaveWelcomeViewStep.cpp b/raveos-calamares-module/welcome/RaveWelcomeViewStep.cpp index c2d58c7..2f7c1ea 100644 --- a/raveos-calamares-module/welcome/RaveWelcomeViewStep.cpp +++ b/raveos-calamares-module/welcome/RaveWelcomeViewStep.cpp @@ -1,25 +1,64 @@ #include "RaveWelcomeViewStep.h" -#include <QComboBox> +#include "RaveBillentyuzet.h" + +#include <QButtonGroup> #include <QFrame> +#include <QGridLayout> #include <QHBoxLayout> #include <QLabel> #include <QLocale> #include <QPainter> #include <QProcess> #include <QPixmap> -#include <QResizeEvent> +#include <QPushButton> #include <QVBoxLayout> #include <Branding.h> #include <GlobalStorage.h> #include <JobQueue.h> +#include <ViewManager.h> #include <locale/Translation.h> -#include <locale/TranslationsModel.h> #include <utils/Retranslator.h> CALAMARES_PLUGIN_FACTORY_DEFINITION(RaveWelcomeViewStepFactory, registerPlugin<RaveWelcomeViewStep>();) +namespace +{ +struct LanguageTexts +{ + QString title; + QString next; + QString installer; +}; + +LanguageTexts textsFor(const QString& localeId) +{ + if (localeId.startsWith(QLatin1String("hu"))) + return { QStringLiteral("VÁLASSZ NYELVET"), QStringLiteral("Tovább"), QStringLiteral("TELEPÍTŐ") }; + if (localeId.startsWith(QLatin1String("de"))) + return { QStringLiteral("SPRACHE WÄHLEN"), QStringLiteral("Weiter"), QStringLiteral("INSTALLATION") }; + return { QStringLiteral("CHOOSE YOUR LANGUAGE"), QStringLiteral("Next"), QStringLiteral("INSTALLER") }; +} + +QString fullLocaleName(const QString& localeId) +{ + QString lang = QLocale(localeId).name(); + if (lang.isEmpty()) + lang = localeId; + return lang.contains('.') ? lang : lang + ".UTF-8"; +} + +QString nativeName(const QString& localeId) +{ + QString name = QLocale(localeId).nativeLanguageName(); + if (name.isEmpty()) + return localeId; + name[0] = name[0].toUpper(); + return name; +} +} + class BgWidget : public QWidget { public: @@ -30,9 +69,16 @@ public: protected: void paintEvent(QPaintEvent*) override { - if (m_pixmap.isNull()) return; QPainter p(this); - p.drawPixmap(rect(), m_pixmap); + p.fillRect(rect(), QColor(0x1a, 0x1b, 0x1d)); + if (m_pixmap.isNull()) return; + const QSize scaled = m_pixmap.size().scaled(size(), Qt::KeepAspectRatioByExpanding); + const QRect target((width() - scaled.width()) / 2, + (height() - scaled.height()) * 4 / 10, + scaled.width(), + scaled.height()); + p.setRenderHint(QPainter::SmoothPixmapTransform); + p.drawPixmap(target, m_pixmap); } private: @@ -42,7 +88,8 @@ private: RaveWelcomeViewStep::RaveWelcomeViewStep(QObject* parent) : Calamares::ViewStep(parent) { - m_localeIds = { "de", "en", "en_GB", "hu" }; + RaveBillentyuzet::regisztral(); + m_localeIds = { "hu", "en", "en_GB", "de" }; } RaveWelcomeViewStep::~RaveWelcomeViewStep() @@ -56,13 +103,13 @@ QString RaveWelcomeViewStep::prettyName() const const QString locale = getLocale(); if (locale.startsWith("hu")) { - return QStringLiteral("Üdvözlés"); + return QStringLiteral("Nyelv"); } if (locale.startsWith("de")) { - return QStringLiteral("Willkommen"); + return QStringLiteral("Sprache"); } - return tr("Welcome"); + return tr("Language"); } QString RaveWelcomeViewStep::getLocale() const @@ -103,53 +150,114 @@ void RaveWelcomeViewStep::buildWidget() if (!imgPath.isEmpty()) bg->setPixmap(QPixmap(imgPath)); - auto* bar = new QFrame(); - bar->setObjectName("ravewelcomeBar"); - bar->setFixedHeight(58); + m_tag = new QLabel(); + m_tag->setObjectName("ravewelcomeTag"); - m_langCombo = new QComboBox(bar); - m_langCombo->setObjectName("ravewelcomeCombo"); - m_langCombo->setFixedHeight(40); - m_langCombo->setMinimumWidth(300); + auto* panel = new QFrame(); + panel->setObjectName("ravewelcomeBar"); - auto* model = new Calamares::Locale::TranslationsModel(m_localeIds, m_langCombo); - m_langCombo->setModel(model); + m_title = new QLabel(); + m_title->setObjectName("ravewelcomeTitle"); + m_localeLabel = new QLabel(); + m_localeLabel->setObjectName("ravewelcomeLocale"); - QLocale sys = QLocale::system(); - QString sysName = sys.name(); - m_currentLocaleIndex = 0; + auto* headerLayout = new QHBoxLayout(); + headerLayout->setContentsMargins(0, 0, 0, 0); + headerLayout->addWidget(m_title); + headerLayout->addStretch(); + headerLayout->addWidget(m_localeLabel, 0, Qt::AlignBottom); + + m_langButtons = new QButtonGroup(panel); + m_langButtons->setExclusive(true); + auto* langLayout = new QGridLayout(); + langLayout->setContentsMargins(0, 0, 0, 0); + langLayout->setHorizontalSpacing(8); for (int i = 0; i < m_localeIds.size(); ++i) { - if (m_localeIds[i] == sysName || sysName.startsWith(m_localeIds[i].left(2))) - { - m_currentLocaleIndex = i; - break; - } + auto* button = new QPushButton(nativeName(m_localeIds[i])); + button->setObjectName("ravewelcomeLang"); + button->setCheckable(true); + button->setMinimumHeight(48); + button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_langButtons->addButton(button, i); + langLayout->addWidget(button, 0, i); + } + + m_next = new QPushButton(); + m_next->setObjectName("ravewelcomeNext"); + m_next->setMinimumHeight(48); + connect(m_next, &QPushButton::clicked, this, []() + { + if (auto* vm = Calamares::ViewManager::instance()) + vm->next(); + }); + + auto* actionLayout = new QHBoxLayout(); + actionLayout->setContentsMargins(0, 0, 0, 0); + actionLayout->setSpacing(12); + actionLayout->addLayout(langLayout, 1); + actionLayout->addWidget(m_next); + + auto* panelLayout = new QVBoxLayout(panel); + panelLayout->setContentsMargins(24, 20, 24, 20); + panelLayout->setSpacing(14); + panelLayout->addLayout(headerLayout); + panelLayout->addLayout(actionLayout); + + const QString sysName = QLocale::system().name(); + int exact = -1; + int prefix = -1; + for (int i = 0; i < m_localeIds.size(); ++i) + { + if (m_localeIds[i] == sysName) + exact = i; + else if (prefix < 0 && sysName.startsWith(m_localeIds[i].left(2))) + prefix = i; } - int enIdx = m_localeIds.indexOf("en"); - if (enIdx >= 0 && m_currentLocaleIndex == 0 && m_localeIds[0] != "en") - m_currentLocaleIndex = enIdx; + if (exact >= 0) + m_currentLocaleIndex = exact; + else if (prefix >= 0) + m_currentLocaleIndex = prefix; + else + m_currentLocaleIndex = qMax(0, m_localeIds.indexOf("en")); - m_langCombo->setCurrentIndex(m_currentLocaleIndex); + if (auto* button = m_langButtons->button(m_currentLocaleIndex)) + button->setChecked(true); applyLiveKeyboardLayout(m_localeIds.value(m_currentLocaleIndex)); - connect(m_langCombo, QOverload<int>::of(&QComboBox::activated), + connect(m_langButtons, &QButtonGroup::idClicked, this, &RaveWelcomeViewStep::onLanguageChanged); - auto* barLayout = new QHBoxLayout(bar); - barLayout->setContentsMargins(16, 0, 16, 0); - barLayout->addStretch(); - barLayout->addWidget(m_langCombo); - barLayout->addStretch(); - auto* mainLayout = new QVBoxLayout(bg); - mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); + mainLayout->addWidget(m_tag, 0, Qt::AlignLeft | Qt::AlignTop); mainLayout->addStretch(); - mainLayout->addWidget(bar); + mainLayout->addWidget(panel); m_widget = bg; + updateTexts(); +} + +void RaveWelcomeViewStep::updateTexts() +{ + const QString localeId = m_localeIds.value(m_currentLocaleIndex); + const LanguageTexts texts = textsFor(localeId); + + QString version; + if (Calamares::Branding::instance()) + version = Calamares::Branding::instance()->string(Calamares::Branding::Version); + const QString product = version.isEmpty() ? QStringLiteral("RAVEOS") : QStringLiteral("RAVEOS ") + version; + + m_tag->setText(product + QStringLiteral(" · ") + texts.installer); + m_title->setText(texts.title); + m_localeLabel->setText(fullLocaleName(localeId)); + m_next->setText(texts.next); +} + +QSize RaveWelcomeViewStep::widgetMargins(Qt::Orientations) +{ + return QSize(28, 24); } QWidget* RaveWelcomeViewStep::widget() @@ -172,10 +280,10 @@ void RaveWelcomeViewStep::onLanguageChanged(int index) Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); if (gs) { - QString lang = QLocale(localeId).name(); // e.g. "hu" -> "hu_HU" + QString lang = QLocale(localeId).name(); if (lang.isEmpty()) lang = localeId; - QString fullLocale = lang.contains('.') ? lang : lang + ".UTF-8"; + const QString fullLocale = fullLocaleName(localeId); const char* lcKeys[] = { "LANG", "LC_NUMERIC", "LC_TIME", "LC_MONETARY", "LC_PAPER", @@ -195,6 +303,7 @@ void RaveWelcomeViewStep::onLanguageChanged(int index) Calamares::installTranslator(tid, brandingTranslationsPrefix()); applyLiveKeyboardLayout(localeId); + updateTexts(); } QString RaveWelcomeViewStep::brandingTranslationsPrefix() const diff --git a/raveos-calamares-module/welcome/RaveWelcomeViewStep.h b/raveos-calamares-module/welcome/RaveWelcomeViewStep.h index 87b42dd..10289e9 100644 --- a/raveos-calamares-module/welcome/RaveWelcomeViewStep.h +++ b/raveos-calamares-module/welcome/RaveWelcomeViewStep.h @@ -8,8 +8,9 @@ #include <viewpages/ViewStep.h> #include <Job.h> -class QComboBox; +class QButtonGroup; class QLabel; +class QPushButton; class PLUGINDLLEXPORT RaveWelcomeViewStep : public Calamares::ViewStep { @@ -21,6 +22,7 @@ public: QString prettyName() const override; QWidget* widget() override; + QSize widgetMargins(Qt::Orientations panelSides) override; bool isNextEnabled() const override; bool isBackEnabled() const override; @@ -36,13 +38,17 @@ private slots: private: void buildWidget(); + void updateTexts(); QString getLocale() const; QString brandingTranslationsPrefix() const; void applyLiveKeyboardLayout(const QString& localeId); - QWidget* m_widget = nullptr; - QLabel* m_bgLabel = nullptr; - QComboBox* m_langCombo = nullptr; + QWidget* m_widget = nullptr; + QButtonGroup* m_langButtons = nullptr; + QLabel* m_tag = nullptr; + QLabel* m_title = nullptr; + QLabel* m_localeLabel = nullptr; + QPushButton* m_next = nullptr; QStringList m_localeIds; int m_currentLocaleIndex = 0; diff --git a/raveos-calamares-module/welcome/ravewelcome.conf b/raveos-calamares-module/welcome/ravewelcome.conf deleted file mode 100644 index 6acb1c7..0000000 --- a/raveos-calamares-module/welcome/ravewelcome.conf +++ /dev/null @@ -1,7 +0,0 @@ ---- -# Available languages (must match the branding/lang directory) -languages: - - de - - en - - en_GB - - hu |