[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdereview/keyboard2
From: Andriy Rysin <arysin () gmail ! com>
Date: 2010-05-01 17:21:28
Message-ID: 20100501172128.8AB08AC8AB () svn ! kde ! org
[Download RAW message or body]
SVN commit 1121560 by rysin:
allow moving layouts; initialize with currentl layouts when list empty; cleanup
M +4 -5 TODO
M +5 -3 kcm_add_layout_dialog.cpp
M +26 -6 kcm_keyboard.ui
M +130 -20 kcm_keyboard_widget.cpp
M +5 -0 kcm_keyboard_widget.h
M +39 -0 kcm_view_models.cpp
M +7 -1 kcm_view_models.h
M +8 -5 keyboard_config.cpp
--- trunk/kdereview/keyboard2/TODO #1121559:1121560
@@ -1,14 +1,12 @@
Core:
* better handling when layouts set manually and not present in config
-KCM UI
+KCM UI:
* allow changing variant without re-adding layout
-* allow changing layout order
-* show nicer flag
-* show current layouts when "configure layouts" disabled
* handle no layouts/1 layout nicer
KCM UI cleanup:
+* show nicer flag in the table
* layouts, sizes, alignment etc in kcm
plasma applet:
@@ -30,4 +28,5 @@
External improvements:
* Change KStatusNotifierItem menu window to be real popup window
* Add KSharedConfig::configChanged() signal
-* move iso-codes to kdesupport
+* make iso-codes external package
+* make flags external package
--- trunk/kdereview/keyboard2/kcm_add_layout_dialog.cpp #1121559:1121560
@@ -20,8 +20,6 @@
#include <klocalizedstring.h>
-#include <QtCore/QDebug>
-
#include "xkb_rules.h"
#include "flags.h"
#include "iso_codes.h"
@@ -63,7 +61,6 @@
void AddLayoutDialog::languageChanged(int langIdx)
{
QString lang = layoutDialogUi->languageComboBox->itemData(langIdx).toString();
- qDebug() << "selected lang" << lang;
QPixmap emptyPixmap(layoutDialogUi->layoutComboBox->iconSize());
emptyPixmap.fill(Qt::transparent);
@@ -71,13 +68,18 @@
layoutDialogUi->layoutComboBox->clear();
foreach(const LayoutInfo* layoutInfo, rules->layoutInfos) {
if( lang.isEmpty() || layoutInfo->languages.contains(lang) ) {
+ if( flags ) {
QIcon icon(flags->getIcon(layoutInfo->name));
if( icon.isNull() ) {
icon = QIcon(emptyPixmap); // align text with no icons
}
layoutDialogUi->layoutComboBox->addItem(icon, layoutInfo->description, \
layoutInfo->name); }
+ else {
+ layoutDialogUi->layoutComboBox->addItem(layoutInfo->description, \
layoutInfo->name); }
+ }
+ }
layoutDialogUi->layoutComboBox->setCurrentIndex(0);
layoutChanged(0);
}
--- trunk/kdereview/keyboard2/kcm_keyboard.ui #1121559:1121560
@@ -11,7 +11,7 @@
</rect>
</property>
<property name="currentIndex">
- <number>1</number>
+ <number>0</number>
</property>
<widget class="QWidget" name="tabHardware">
<attribute name="title">
@@ -21,9 +21,9 @@
<property name="geometry">
<rect>
<x>4</x>
- <y>51</y>
+ <y>33</y>
<width>646</width>
- <height>361</height>
+ <height>379</height>
</rect>
</property>
<property name="sizePolicy">
@@ -33,13 +33,13 @@
</sizepolicy>
</property>
</widget>
- <widget class="QWidget" name="layoutWidget">
+ <widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>5</x>
<y>5</y>
- <width>641</width>
- <height>27</height>
+ <width>331</width>
+ <height>25</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -123,6 +123,26 @@
</widget>
</item>
<item>
+ <widget class="QPushButton" name="moveUpBtn">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="moveDownBtn">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
--- trunk/kdereview/keyboard2/kcm_keyboard_widget.cpp #1121559:1121560
@@ -139,7 +139,7 @@
return;
}
- AddLayoutDialog dialog(rules, flags, this);
+ AddLayoutDialog dialog(rules, keyboardConfig->showFlag ? flags : NULL, this);
dialog.setModal(true);
if( dialog.exec() == QDialog::Accepted ) {
keyboardConfig->layouts.append( dialog.getSelectedLayoutConfig() );
@@ -148,33 +148,24 @@
}
}
-void KCMKeyboardWidget::removeLayout()
-{
- QModelIndexList selected = \
uiWidget->layoutsTableView->selectionModel()->selectedIndexes();
- foreach(const QModelIndex& idx, selected) {
- if( idx.column() == 0 ) {
- keyboardConfig->layouts.removeAt(idx.row());
- }
- }
- layoutsTableModel->refresh();
- uiChanged();
-}
-
-void KCMKeyboardWidget::layoutSelectionChanged()
-{
- QModelIndexList selected = \
uiWidget->layoutsTableView->selectionModel()->selectedIndexes();
- uiWidget->removeLayoutBtn->setEnabled( ! selected.isEmpty() );
-}
-
void KCMKeyboardWidget::initializeLayoutsUI()
{
layoutsTableModel = new LayoutsTableModel(rules, flags, keyboardConfig, \
uiWidget->layoutsTableView); \
uiWidget->layoutsTableView->setModel(layoutsTableModel); connect(layoutsTableModel, \
SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, \
SLOT(uiChanged()));
+#ifdef DRAG_ENABLED
+ uiWidget->layoutsTableView->setDragEnabled(true);
+ uiWidget->layoutsTableView->setAcceptDrops(true);
+#endif
// connect(layoutsTableModel, SIGNAL(), this, SLOT(uiChanged()));
// connect(uiWidget->layoutsTableView, SIGNAL(clicked(const QModelIndex &)), \
this, SLOT(layoutCellClicked(const QModelIndex &)));
+ uiWidget->moveUpBtn->setIcon(KIcon("arrow-up"));
+ uiWidget->moveDownBtn->setIcon(KIcon("arrow-down"));
+// uiWidget->moveUpBtn->setArrowType(Qt::UpArrow);
+// uiWidget->moveUpBtn->setArrowType(Qt::UpDown);
+
KIcon clearIcon = qApp->isLeftToRight() ? KIcon("edit-clear-locationbar-rtl") : \
KIcon("edit-clear-locationbar-ltr"); uiWidget->xkbGrpClearBtn->setIcon(clearIcon);
uiWidget->xkb3rdLevelClearBtn->setIcon(clearIcon);
@@ -192,6 +183,11 @@
connect(uiWidget->showFlagChk, SIGNAL(clicked(bool)), this, SLOT(uiChanged()));
+// connect(uiWidget->moveUpBtn, SIGNAL(triggered(QAction*)), this, SLOT(moveUp()));
+// connect(uiWidget->moveDownBtn, SIGNAL(triggered(QAction*)), this, \
SLOT(moveDown())); + connect(uiWidget->moveUpBtn, SIGNAL(clicked(bool)), this, \
SLOT(moveUp())); + connect(uiWidget->moveDownBtn, SIGNAL(clicked(bool)), this, \
SLOT(moveDown())); +
connect(uiWidget->xkbGrpClearBtn, SIGNAL(clicked(bool)), this, \
SLOT(clearGroupShortcuts())); connect(uiWidget->xkb3rdLevelClearBtn, \
SIGNAL(clicked(bool)), this, SLOT(clear3rdLevelShortcuts()));
@@ -206,9 +202,114 @@
connect(uiWidget->configureLayoutsChk, SIGNAL(toggled(bool)), \
uiWidget->layoutsGroupBox, SLOT(setEnabled(bool))); \
connect(uiWidget->configureLayoutsChk, SIGNAL(toggled(bool)), \
uiWidget->shortcutsGroupBox, SLOT(setEnabled(bool))); \
connect(uiWidget->configureLayoutsChk, SIGNAL(toggled(bool)), \
uiWidget->switchingPolicyButtonGroup, SLOT(setEnabled(bool)));
- connect(uiWidget->configureLayoutsChk, SIGNAL(toggled(bool)), this, \
SLOT(uiChanged())); + connect(uiWidget->configureLayoutsChk, SIGNAL(toggled(bool)), \
this, SLOT(configureLayoutsChanged())); }
+void KCMKeyboardWidget::configureLayoutsChanged()
+{
+ if( uiWidget->configureLayoutsChk->isChecked() && keyboardConfig->layouts.isEmpty() \
) { + populateWithCurrentLayouts();
+ }
+ uiChanged();
+}
+
+static QPair<int, int> getSelectedRowRange(const QModelIndexList& selected)
+{
+ if( selected.isEmpty() ) {
+ return QPair<int, int>(-1, -1);
+ }
+
+ QList<int> rows;
+ foreach(const QModelIndex& index, selected) {
+ rows << index.row();
+ }
+ qSort(rows);
+ return QPair<int, int>(rows[0], rows[rows.size()-1]);
+}
+
+void KCMKeyboardWidget::layoutSelectionChanged()
+{
+ QModelIndexList selected = \
uiWidget->layoutsTableView->selectionModel()->selectedIndexes(); \
+ uiWidget->removeLayoutBtn->setEnabled( ! selected.isEmpty() ); + QPair<int, int> \
rowsRange( getSelectedRowRange(selected) ); + uiWidget->moveUpBtn->setEnabled( ! \
selected.isEmpty() && rowsRange.first > 0); + uiWidget->moveDownBtn->setEnabled( ! \
selected.isEmpty() && rowsRange.second < keyboardConfig->layouts.size()-1 ); +}
+
+void KCMKeyboardWidget::removeLayout()
+{
+ if( ! uiWidget->layoutsTableView->selectionModel()->hasSelection() )
+ return;
+
+ QModelIndexList selected = \
uiWidget->layoutsTableView->selectionModel()->selectedIndexes(); + QPair<int, int> \
rowsRange( getSelectedRowRange(selected) ); + foreach(const QModelIndex& idx, \
selected) { + if( idx.column() == 0 ) {
+ keyboardConfig->layouts.removeAt(rowsRange.first);
+ }
+ }
+ layoutsTableModel->refresh();
+ uiChanged();
+
+ if( keyboardConfig->layouts.size() > 0 ) {
+ int rowToSelect = rowsRange.first;
+ if( rowToSelect >= keyboardConfig->layouts.size() ) {
+ rowToSelect--;
+ }
+
+ QModelIndex topLeft = layoutsTableModel->index(rowToSelect, 0, \
QModelIndex()); + QModelIndex bottomRight = \
layoutsTableModel->index(rowToSelect, layoutsTableModel->columnCount(topLeft)-1, \
QModelIndex()); + QItemSelection selection(topLeft, bottomRight);
+ uiWidget->layoutsTableView->selectionModel()->select(selection, \
QItemSelectionModel::SelectCurrent); + uiWidget->layoutsTableView->setFocus();
+ }
+
+ layoutSelectionChanged();
+}
+
+void KCMKeyboardWidget::moveUp()
+{
+ moveSelectedLayouts(-1);
+}
+
+void KCMKeyboardWidget::moveDown()
+{
+ moveSelectedLayouts(1);
+}
+
+void KCMKeyboardWidget::moveSelectedLayouts(int shift)
+{
+ QItemSelectionModel* selectionModel = \
uiWidget->layoutsTableView->selectionModel(); + if( selectionModel == NULL || \
!selectionModel->hasSelection() ) + return;
+
+ QModelIndexList selected = selectionModel->selectedRows();
+ if( selected.count() < 1 )
+ return;
+
+ int newFirstRow = selected[0].row() + shift;
+ int newLastRow = selected[ selected.size()-1 ].row() + shift;
+
+ if( newFirstRow >= 0 && newLastRow <= keyboardConfig->layouts.size() - 1 ) {
+ QList<int> selectionRows;
+ foreach(const QModelIndex& index, selected) {
+ int newRowIndex = index.row() + shift;
+ keyboardConfig->layouts.move(index.row(), newRowIndex);
+ selectionRows << newRowIndex;
+ }
+ uiChanged();
+
+ QItemSelection selection;
+ foreach(int row, selectionRows) {
+ QModelIndex topLeft = layoutsTableModel->index(row, 0, QModelIndex());
+ QModelIndex bottomRight = layoutsTableModel->index(row, \
layoutsTableModel->columnCount(topLeft)-1, QModelIndex()); + selection << \
QItemSelectionRange(topLeft, bottomRight); + }
+ uiWidget->layoutsTableView->selectionModel()->select(selection, \
QItemSelectionModel::SelectCurrent); + uiWidget->layoutsTableView->setFocus();
+ }
+}
+
void KCMKeyboardWidget::scrollToGroupShortcut()
{
this->setCurrentIndex(TAB_ADVANCED);
@@ -361,3 +462,12 @@
uiWidget->keyboardModelComboBox->setCurrentIndex(idx);
}
}
+
+void KCMKeyboardWidget::populateWithCurrentLayouts()
+{
+ QStringList layoutNames = X11Helper::getLayoutsList();
+ foreach(QString fullLayoutName, layoutNames) {
+ LayoutConfig layoutConfig( LayoutConfig::createLayoutConfig(fullLayoutName) );
+ keyboardConfig->layouts.append(layoutConfig);
+ }
+}
--- trunk/kdereview/keyboard2/kcm_keyboard_widget.h #1121559:1121560
@@ -61,6 +61,9 @@
void clearGroupShortcuts();
void clear3rdLevelShortcuts();
void updateXkbShortcutsButtons();
+ void moveUp();
+ void moveDown();
+ void configureLayoutsChanged();
private:
Rules *rules;
@@ -83,6 +86,8 @@
void updateSwitcingPolicyUI();
void updateXkbShortcutButton(const QString& groupName, QPushButton* button);
void clearXkbGroup(const QString& groupName);
+ void moveSelectedLayouts(int shift);
+ void populateWithCurrentLayouts();
};
--- trunk/kdereview/keyboard2/kcm_view_models.cpp #1121559:1121560
@@ -23,6 +23,10 @@
#include <QtGui/QTreeView>
#include <QtGui/QComboBox>
+#ifdef DRAG_ENABLED
+#include <QtCore/QMimeData>
+#endif
+
#include "keyboard_config.h"
#include "xkb_rules.h"
#include "flags.h"
@@ -69,9 +73,44 @@
flags |= Qt::ItemIsEditable;
}
+#ifdef DRAG_ENABLED
+ flags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
+#endif
+
return flags;
}
+#ifdef DRAG_ENABLED
+QStringList LayoutsTableModel::mimeTypes() const
+{
+ QStringList types;
+ types << "application/keyboard-layout-item";
+ return types;
+}
+
+QMimeData *LayoutsTableModel::mimeData(const QModelIndexList &indexes) const
+ {
+ QMimeData *mimeData = new QMimeData();
+ QByteArray encodedData;
+
+ QDataStream stream(&encodedData, QIODevice::WriteOnly);
+
+ QSet<int> rows;
+ foreach (QModelIndex index, indexes) {
+ if (index.isValid()) {
+ rows << index.row();
+ }
+ }
+ foreach (int row, rows) {
+ stream << row;
+ kDebug() << "idx: " << row;
+ }
+
+ mimeData->setData("application/keyboard-layout-item", encodedData);
+ return mimeData;
+}
+#endif
+
QVariant LayoutsTableModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
--- trunk/kdereview/keyboard2/kcm_view_models.h #1121559:1121560
@@ -43,7 +43,13 @@
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
-
+#ifdef DRAG_ENABLED
+ Qt::DropActions supportedDropActions() const {
+ return Qt::MoveAction;
+ }
+ QStringList mimeTypes() const;
+ QMimeData *mimeData(const QModelIndexList &indexes) const;
+#endif
void refresh();
private:
--- trunk/kdereview/keyboard2/keyboard_config.cpp #1121559:1121560
@@ -25,7 +25,7 @@
static const char* SWITCHING_POLICIES[] = {"Global", "Desktop", "WinClass", \
"Window", NULL }; static const char* LIST_SEPARATOR = ",";
-static const char* DEFAULT_LAYOUT = "us";
+//static const char* DEFAULT_LAYOUT = "us";
static const char* DEFAULT_MODEL = "pc104";
static const QString CONFIG_FILENAME("kxkbrc");
@@ -73,7 +73,7 @@
// init layouts options
configureLayouts = false;
layouts.clear();
- layouts.append(LayoutConfig::createLayoutConfig(DEFAULT_LAYOUT));
+// layouts.append(LayoutConfig::createLayoutConfig(DEFAULT_LAYOUT));
// switch cotrol options
switchingPolicy = SWITCH_POLICY_GLOBAL;
@@ -99,13 +99,16 @@
configureLayouts = config.readEntry("Use", false);
QString layoutsString = config.readEntry("LayoutList", "");
QStringList layoutStrings = layoutsString.split(LIST_SEPARATOR, \
QString::SkipEmptyParts);
- if( layoutStrings.isEmpty() ) {
- layoutStrings.append(DEFAULT_LAYOUT);
- }
+// if( layoutStrings.isEmpty() ) {
+// layoutStrings.append(DEFAULT_LAYOUT);
+// }
layouts.clear();
foreach(const QString& layoutString, layoutStrings) {
layouts.append(LayoutConfig::createLayoutConfig(layoutString));
}
+ if( layouts.isEmpty() ) {
+ configureLayouts = false;
+ }
QString layoutMode = config.readEntry("SwitchMode", "Global");
switchingPolicy = static_cast<SwitchingPolicy>(findStringIndex(SWITCHING_POLICIES, \
layoutMode, SWITCH_POLICY_GLOBAL));
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic