Commit 48d36f3d authored by Weng Xuetian's avatar Weng Xuetian

display layout :D

parent 00858d8d
......@@ -187,7 +187,7 @@ FcitxXkbInitDefaultLayout (QString& model, QString& option)
return true;
}
void KeyboardLayoutWidget::setLayout(const QString& layout, const QString& variant)
void KeyboardLayoutWidget::setKeyboardLayout(const QString& layout, const QString& variant)
{
XkbRF_VarDefsRec rdefs;
XkbComponentNamesRec rnames;
......@@ -274,8 +274,16 @@ void KeyboardLayoutWidget::release()
{
physicalIndicators.clear();
physicalIndicatorsSize = 0;
delete[] keys;
delete[] colors;
if (keys) {
delete[] keys;
keys = NULL;
}
if (colors) {
delete[] colors;
colors = NULL;
}
foreach(DrawingItem* item, keyboardItems) {
switch (item->type) {
case KEYBOARD_DRAWING_ITEM_TYPE_INVALID:
......
......@@ -77,7 +77,7 @@ public:
explicit KeyboardLayoutWidget(QWidget* parent = 0);
virtual ~KeyboardLayoutWidget();
void setGroup(int group);
void setLayout(const QString& layout, const QString& variant);
void setKeyboardLayout(const QString& layout, const QString& variant);
void generatePixmap(bool force = false);
protected:
......
......@@ -65,7 +65,7 @@ int main(int argc, char* argv[])
widget.setGroup(group);
}
else if (!layout.isNull()) {
widget.setLayout(layout, variant);
widget.setKeyboardLayout(layout, variant);
}
mainWindow.setCentralWidget(&widget);
......
include_directories(${PROJECT_SOURCE_DIR}/layout)
set(kcm_SRCS
main.cpp
......@@ -16,6 +16,7 @@ set(kcm_SRCS
FcitxLayout.cpp
FcitxIMConfigDialog.cpp
qtkeytrans.cpp
../layout/KeyboardLayoutWidget.cpp
)
set_property(
......@@ -50,6 +51,8 @@ target_link_libraries(kcm_fcitx
${FCITX4_FCITX_CONFIG_LIBRARIES}
${FCITX4_FCITX_LIBRARIES}
${LIBINTL_LIBRARY}
${XKBFILE_LIBRARIES}
${X11_X11_LIB}
)
install(TARGETS kcm_fcitx DESTINATION ${PLUGIN_INSTALL_DIR})
......
......@@ -8,6 +8,7 @@
#include "FcitxIMConfigDialog.h"
#include "ConfigDescManager.h"
#include "FcitxConfigPage.h"
#include "KeyboardLayoutWidget.h"
Fcitx::FcitxIMConfigDialog::FcitxIMConfigDialog(const QString& imName, const FcitxAddon* addon, QWidget* parent): KDialog(parent)
,m_connection(QDBusConnection::sessionBus())
......@@ -69,8 +70,31 @@ Fcitx::FcitxIMConfigDialog::FcitxIMConfigDialog(const QString& imName, const Fci
l->addWidget(label);
l->addWidget(m_layoutCombobox);
connect(m_layoutCombobox, SIGNAL(currentIndexChanged(int)), this, SLOT(layoutComboBoxChanged()));
m_layoutWidget = new KeyboardLayoutWidget(this);
m_layoutWidget->setMinimumSize(QSize(400, 200));
m_layoutWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
l->addWidget(m_layoutWidget);
layoutComboBoxChanged();
}
}
else {
KeyboardLayoutWidget* layoutWidget = new KeyboardLayoutWidget(this);
layoutWidget->setMinimumSize(QSize(400, 200));
layoutWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QString layoutstring = imName.mid(strlen("fcitx-keyboard-"));
int p = layoutstring.indexOf("-");
QString layout, variant;
if (p < 0) {
layout = layoutstring;
}
else {
layout = layoutstring.mid(0, p);
variant = layoutstring.mid(p + 1);
}
layoutWidget->setKeyboardLayout(layout, variant);
l->addWidget(layoutWidget);
}
FcitxConfigFileDesc* cfdesc = ConfigDescManager::instance()->GetConfigDesc(QString::fromUtf8(addon->name).append(".desc"));
......@@ -111,3 +135,17 @@ void Fcitx::FcitxIMConfigDialog::onButtonClicked(KDialog::ButtonCode code)
if (m_configPage)
m_configPage->buttonClicked(code);
}
void Fcitx::FcitxIMConfigDialog::layoutComboBoxChanged()
{
if (!m_layoutCombobox || !m_layoutWidget)
return;
int idx = m_layoutCombobox->currentIndex();
if (idx != 0) {
m_layoutWidget->setKeyboardLayout(m_layoutList.at(idx - 1).layout(), m_layoutList.at(idx - 1).variant());
m_layoutWidget->show();
}
else
m_layoutWidget->hide();
}
......@@ -2,6 +2,7 @@
#include <fcitx/addon.h>
#include "org.fcitx.Fcitx.Keyboard.h"
class KeyboardLayoutWidget;
class KComboBox;
namespace Fcitx {
......@@ -14,6 +15,7 @@ public:
private slots:
void onButtonClicked(KDialog::ButtonCode code);
void layoutComboBoxChanged();
private:
QDBusConnection m_connection;
......@@ -22,5 +24,6 @@ private:
KComboBox* m_layoutCombobox;
FcitxConfigPage* m_configPage;
FcitxLayoutList m_layoutList;
KeyboardLayoutWidget* m_layoutWidget;
};
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment