[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/kcontrol/keyboard
From:       Andriy Rysin <arysin () gmail ! com>
Date:       2010-08-26 13:11:09
Message-ID: 20100826131109.ECD51AC857 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1168345 by rysin:

kcm_keyboard UI improvements to remove confusion about flag/label mode work
BUG: 244145


 M  +17 -0     kcm_add_layout_dialog.cpp  
 M  +26 -2     kcm_add_layout_dialog.ui  
 M  +10 -3     kcm_keyboard_widget.cpp  
 M  +57 -2     kcm_view_models.cpp  
 M  +18 -2     kcm_view_models.h  
 M  +2 -0      x11_helper.cpp  
 M  +2 -0      x11_helper.h  


--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/kcm_add_layout_dialog.cpp \
#1168344:1168345 @@ -53,6 +53,16 @@
     layoutDialogUi->languageComboBox->model()->sort(0);
 	layoutDialogUi->languageComboBox->insertItem(0, i18n("Any language"), "");
 	layoutDialogUi->languageComboBox->setCurrentIndex(0);
+
+	bool noLabel = flags != NULL;
+	if( noLabel ) {
+		layoutDialogUi->labelLabel->setVisible(false);
+		layoutDialogUi->labelEdit->setVisible(false);
+	}
+	else {
+		layoutDialogUi->labelEdit->setMaxLength(LayoutUnit::MAX_LABEL_LENGTH);
+	}
+
     languageChanged(0);
 
 	connect(layoutDialogUi->languageComboBox, SIGNAL(activated(int)), this, \
SLOT(languageChanged(int))); @@ -104,6 +114,8 @@
 	layoutDialogUi->variantComboBox->insertItem(0, i18nc("variant", "Default"), "");
 	layoutDialogUi->variantComboBox->setCurrentIndex(0);
 
+	layoutDialogUi->labelEdit->setText(layoutName);
+
 	selectedLayout = layoutName;
 }
 
@@ -111,5 +123,10 @@
 {
 	selectedLayoutUnit.layout = \
layoutDialogUi->layoutComboBox->itemData(layoutDialogUi->layoutComboBox->currentIndex()).toString();
  selectedLayoutUnit.variant = \
layoutDialogUi->variantComboBox->itemData(layoutDialogUi->variantComboBox->currentIndex()).toString();
 +	QString label = layoutDialogUi->labelEdit->text();
+	if( label == selectedLayoutUnit.layout ) {
+		label = "";
+	}
+	selectedLayoutUnit.setDisplayName( label );
 	QDialog::accept();
 }
--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/kcm_add_layout_dialog.ui \
#1168344:1168345 @@ -22,7 +22,14 @@
     </widget>
    </item>
    <item row="0" column="1">
-    <widget class="QComboBox" name="languageComboBox"/>
+    <widget class="QComboBox" name="languageComboBox">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
    </item>
    <item row="1" column="0">
     <widget class="QLabel" name="label_2">
@@ -44,7 +51,24 @@
    <item row="2" column="1">
     <widget class="QComboBox" name="variantComboBox"/>
    </item>
-   <item row="3" column="0" colspan="2">
+   <item row="3" column="0">
+    <widget class="QLabel" name="labelLabel">
+     <property name="text">
+      <string>Label</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="1">
+    <widget class="QLineEdit" name="labelEdit">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="1">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/kcm_keyboard_widget.cpp \
#1168344:1168345 @@ -184,13 +184,20 @@
 void KCMKeyboardWidget::initializeLayoutsUI()
 {
 	layoutsTableModel = new LayoutsTableModel(rules, flags, keyboardConfig, \
uiWidget->layoutsTableView); \
+	uiWidget->layoutsTableView->setEditTriggers(QAbstractItemView::SelectedClicked | \
QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed | \
QAbstractItemView::AnyKeyPressed);  \
uiWidget->layoutsTableView->setModel(layoutsTableModel); \
+	uiWidget->layoutsTableView->setIconSize( flags->getTransparentPixmap().size() ); +
 	//TODO: do we need to delete this delegate or parent will take care of it?
-	VariantComboDelegate* delegate = new VariantComboDelegate(keyboardConfig, rules, \
                uiWidget->layoutsTableView);
-	uiWidget->layoutsTableView->setItemDelegateForColumn(LayoutsTableModel::VARIANT_COLUMN, \
delegate); +	VariantComboDelegate* variantDelegate = new \
VariantComboDelegate(keyboardConfig, rules, uiWidget->layoutsTableView); \
+	uiWidget->layoutsTableView->setItemDelegateForColumn(LayoutsTableModel::VARIANT_COLUMN, \
variantDelegate); +
+	LabelEditDelegate* labelDelegate = new LabelEditDelegate(keyboardConfig, \
uiWidget->layoutsTableView); \
+	uiWidget->layoutsTableView->setItemDelegateForColumn(LayoutsTableModel::DISPLAY_NAME_COLUMN, \
labelDelegate); +
 	//TODO: is it ok to hardcode sizes? any better approach?
 	uiWidget->layoutsTableView->setColumnWidth(LayoutsTableModel::MAP_COLUMN, 70);
-	uiWidget->layoutsTableView->setColumnWidth(LayoutsTableModel::LAYOUT_COLUMN, 150);
+	uiWidget->layoutsTableView->setColumnWidth(LayoutsTableModel::LAYOUT_COLUMN, 200);
 	uiWidget->layoutsTableView->setColumnWidth(LayoutsTableModel::VARIANT_COLUMN, 250);
 
 	connect(layoutsTableModel, SIGNAL(dataChanged(const QModelIndex &, const \
                QModelIndex &)), this, SLOT(uiChanged()));
--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/kcm_view_models.cpp \
#1168344:1168345 @@ -21,6 +21,8 @@
 #include <klocalizedstring.h>
 #include <QtGui/QTreeView>
 #include <QtGui/QComboBox>
+#include <QtGui/QLineEdit>
+#include <QtGui/QPainter>
 
 #ifdef DRAG_ENABLED
 #include <QtCore/QMimeData>
@@ -122,12 +124,23 @@
 
      if (role == Qt::DecorationRole) {
     	 switch( index.column() ) {
-    	 case MAP_COLUMN: {
+    	 case DISPLAY_NAME_COLUMN: {
     			if( keyboardConfig->showFlag ) {
     				QIcon icon = countryFlags->getIcon(layoutUnit.layout);
     				return icon.isNull() ? countryFlags->getTransparentPixmap() : icon;
     			}
     	 }
+//TODO: show the cells are editable
+//    	 case VARIANT_COLUMN: {
+//    	 case DISPLAY_NAME_COLUMN: {
+//    		 int sz = 5;
+//    		 QPixmap pm = QPixmap(sz, sz+5);
+//    		 pm.fill(Qt::transparent);
+//    		 QPainter p(&pm);
+//    		 QPoint points[] = { QPoint(0, 0), QPoint(0, sz), QPoint(sz, 0) };
+//    		 p.drawPolygon(points, 3);
+//    		 return pm;
+//    	 }
     	 break;
     	 }
      }
@@ -152,7 +165,9 @@
     	 }
          break;
     	 case DISPLAY_NAME_COLUMN:
+ 			if( ! keyboardConfig->showFlag ) {
     		 return layoutUnit.getDisplayName();
+ 			}
     	 break;
     	 }
      }
@@ -167,6 +182,15 @@
     	 default:;
     	 }
      }
+     else if( role == Qt::TextAlignmentRole ) {
+    	 switch( index.column() ) {
+    	 case MAP_COLUMN:
+    	 case DISPLAY_NAME_COLUMN:
+    		 return Qt::AlignCenter;
+    	 break;
+    	 default:;
+    	 }
+     }
      return QVariant();
 }
 
@@ -212,6 +236,37 @@
 }
 
 //
+// LabelEditDelegate
+//
+LabelEditDelegate::LabelEditDelegate(const KeyboardConfig* keyboardConfig_, QObject \
*parent): +	QStyledItemDelegate(parent),
+	keyboardConfig(keyboardConfig_)
+{}
+
+QWidget *LabelEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem \
& option , +		const QModelIndex & index ) const
+{
+	if( keyboardConfig->showFlag )
+		return NULL;
+
+	QWidget* widget = QStyledItemDelegate::createEditor(parent, option, index);
+	QLineEdit* lineEdit = static_cast<QLineEdit*>(widget);
+	if( lineEdit != NULL ) {
+		lineEdit->setMaxLength(LayoutUnit::MAX_LABEL_LENGTH);
+	}
+	return widget;
+}
+
+//void LabelEditDelegate::paint( QPainter * painter, const QStyleOptionViewItem & \
option, const QModelIndex & index ) const +//{
+//	QStyleOptionViewItem option2(option);
+////	option2.decorationPosition =  QStyleOptionViewItem::Right;
+//	option2.decorationAlignment = Qt::AlignHCenter | Qt::AlignVCenter;
+//	QStyledItemDelegate::paint(painter, option2, index);
+//}
+
+
+//
 // VariantComboDelegate
 //
 //TODO: reuse this function in kcm_add_layout_dialog.cpp
@@ -228,7 +283,7 @@
 }
 
 VariantComboDelegate::VariantComboDelegate(const KeyboardConfig* keyboardConfig_, \
                const Rules* rules_, QObject *parent):
-	QItemDelegate(parent),
+	QStyledItemDelegate(parent),
 	keyboardConfig(keyboardConfig_),
 	rules(rules_)
 {}
--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/kcm_view_models.h #1168344:1168345
@@ -22,7 +22,7 @@
 
 #include <QtCore/QAbstractItemModel>
 #include <QtCore/QAbstractTableModel>
-#include <QtGui/QItemDelegate>
+#include <QtGui/QStyledItemDelegate>
 
 class QTreeView;
 class KeyboardConfig;
@@ -64,11 +64,27 @@
      Flags *countryFlags;
 };
 
-class VariantComboDelegate : public QItemDelegate
+class LabelEditDelegate : public QStyledItemDelegate
 {
 	Q_OBJECT
 
 public:
+	LabelEditDelegate(const KeyboardConfig* keyboardConfig, QObject *parent = 0);
+
+	QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
+			const QModelIndex &index) const;
+
+//    void paint(QPainter *painter, const QStyleOptionViewItem &option, const \
QModelIndex &index) const; +
+private:
+    const KeyboardConfig* keyboardConfig;
+};
+
+class VariantComboDelegate : public QStyledItemDelegate
+{
+	Q_OBJECT
+
+public:
 	VariantComboDelegate(const KeyboardConfig* keyboardConfig, const Rules* rules, \
QObject *parent = 0);  
 	QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/x11_helper.cpp #1168344:1168345
@@ -366,3 +366,5 @@
 
 	return layout + LAYOUT_VARIANT_SEPARATOR_PREFIX+variant+LAYOUT_VARIANT_SEPARATOR_SUFFIX;
  }
+
+const int LayoutUnit::MAX_LABEL_LENGTH = 3;
--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/x11_helper.h #1168344:1168345
@@ -64,6 +64,8 @@
 
 
 struct LayoutUnit {
+	static const int MAX_LABEL_LENGTH;
+
 	//TODO: move these to private?
 	QString layout;
 	QString variant;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic