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

List:       kde-core-devel
Subject:    Update: Re: Printing of Shortcuts
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2008-03-20 22:50:49
Message-ID: 20080320225049.GA25720 () morpheus ! apaku ! dnsalias ! org
[Download RAW message or body]

On 18.03.08 00:54:29, Andreas Pakulat wrote:
> Hi,
> 
> I just noticed the April 7th deadline and decided that this feature is
> probably doable until 4.1 (in contrast to the KTE addition I seemingly
> need to do): A print button in KShortcutsEditor.

Updated the patch a bit, new things:

- formatting, the table header is bold and larger than the text, same
  goes for the component names

- added some context to each listed action by also printing the
  whatsthis information (I would've used tooltip as thats usually
  shorter, but unfortunately none of the tooltips in kate are set
  properly). This should fix the issue Jaroslaw pointed out about
  ambiguous actions that happen to sit in different menus but have the
  same text

- a better header of the first page, including the applications short
  description from kaboutdata

The last problems:

- I'm using KGlobalSettings::generalFont() to get a base fontsize and
  I'm not sure thats the right thing to do - any better ideas?

- formatting, I'm not quite 100% satisfied (though I'd check this in as
  is), would be nice if somebody with some more knowledge about good
  text layout could give me some hints

I'm quite satisfied with how it looks now, I'll probably need to fiddle
a bit with the overall page layout as IMHO the table could be a bit
wider.

Also if somebody has a hint how to remove the Component table header
without shrinking that particular column it would be nice. The reason
for that is that IMHO its a bit unneeded to have that there as the
component is always on an own line in the table with the full row merged
and the first column is always empty in all other table rows.

As before the patch is attached as well as the result from printing to
pdf in kate.

Andreas

-- 
An avocado-tone refrigerator would look good on your resume.

["kdeui_shortcut_print.diff" (text/x-diff)]

Index: kdeui/dialogs/kshortcutsdialog_p.h
===================================================================
--- kdeui/dialogs/kshortcutsdialog_p.h	(Revision 787925)
+++ kdeui/dialogs/kshortcutsdialog_p.h	(Arbeitskopie)
@@ -267,6 +267,8 @@
 
     void globalSettingsChangedSystemwide(int);
 
+    void printShortcuts();
+
 // members
     QList<KActionCollection *> actionCollections;
     KShortcutsEditor *q;
Index: kdeui/dialogs/kshortcutseditor.h
===================================================================
--- kdeui/dialogs/kshortcutseditor.h	(Revision 787925)
+++ kdeui/dialogs/kshortcutseditor.h	(Arbeitskopie)
@@ -230,6 +230,7 @@
 	Q_PRIVATE_SLOT(d, void capturedShortcut(QVariant, const QModelIndex &))
 
 	Q_PRIVATE_SLOT(d, void globalSettingsChangedSystemwide(int))
+	Q_PRIVATE_SLOT(d, void printShortcuts())
 
 private:
 	friend class KShortcutsDialog;
Index: kdeui/dialogs/kshortcutseditor.cpp
===================================================================
--- kdeui/dialogs/kshortcutseditor.cpp	(Revision 787925)
+++ kdeui/dialogs/kshortcutseditor.cpp	(Arbeitskopie)
@@ -30,12 +30,19 @@
 
 #include <QHeaderView>
 #include <QTimer>
+#include <QTextDocument>
+#include <QTextTable>
+#include <QTextCursor>
+#include <QTextTableFormat>
+#include <QPrinter>
+#include <QPrintDialog>
 
 #include "kaction.h"
 #include "kactioncollection.h"
 #include "kdebug.h"
 #include "kglobalaccel.h"
 #include "kmessagebox.h"
+#include "kaboutdata.h"
 
 //---------------------------------------------------------------------
 // KShortcutsEditor
@@ -266,6 +273,10 @@
     //hide the editor widget chen its item becomes hidden
     QObject::connect(ui.searchFilter->searchLine(), \
                SIGNAL(hiddenChanged(QTreeWidgetItem *, bool)),
                      delegate, SLOT(hiddenBySearchLine(QTreeWidgetItem *, bool)));
+    
+    QObject::connect(ui.printButton, SIGNAL(clicked()), 
+                     q, SLOT(printShortcuts()));
+    
     ui.searchFilter->setFocus();
 }
 
@@ -543,5 +554,95 @@
     //update display or similar
 }
 
+void KShortcutsEditorPrivate::printShortcuts()
+{
+    QTreeWidgetItem* root = ui.list->invisibleRootItem();
+    QTextDocument doc;
+    QTextCursor cursor(&doc);
+    cursor.beginEditBlock();
+    QTextCharFormat headerFormat;
+    headerFormat.setFontPointSize(KGlobalSettings::generalFont().pointSize()+2.0);
+    headerFormat.setFontUnderline(true);
+    cursor.insertText(i18nc("header for an applications shortcut list","Shortcuts \
for %1:", +                            \
KGlobal::mainComponent().aboutData()->shortDescription()), +                      \
headerFormat); +    QTextTable* table = cursor.insertTable(1,6);
+    QTextTableFormat tableformat;
+    tableformat.setHeaderRowCount(1);
+    tableformat.setCellPadding(4.0);
+    table->setFormat(tableformat);
+    int currow = 0;
+    QTextTableCell cell = table->cellAt(currow,0);
+    QTextCharFormat format = cell.format();
+    format.setFontPointSize(KGlobalSettings::generalFont().pointSize()+1.0);
+    format.setFontWeight( QFont::Bold );
+    cell.setFormat(format);
+    cell.firstCursorPosition().insertText(i18n("Component"));
 
+    cell = table->cellAt(currow,1);
+    cell.setFormat(format);
+    cell.firstCursorPosition().insertText(i18n("Action Name"));
+
+    cell = table->cellAt(currow,2);
+    cell.setFormat(format);
+    cell.firstCursorPosition().insertText(i18n("Main Shortcut"));
+
+    cell = table->cellAt(currow,3);
+    cell.setFormat(format);
+    cell.firstCursorPosition().insertText(i18n("Alternate Shortcut"));
+
+    cell = table->cellAt(currow,4);
+    cell.setFormat(format);
+    cell.firstCursorPosition().insertText(i18n("Global Shortcut"));
+
+    cell = table->cellAt(currow,5);
+    cell.setFormat(format);
+    cell.firstCursorPosition().insertText(i18n("Description"));
+    currow++;
+    for (int i = 0; i < root->childCount(); i++) {
+        QTreeWidgetItem* item = root->child(i);
+        table->insertRows(table->rows(),1);
+        table->mergeCells(currow, 0, 1, 6);
+        cell = table->cellAt(currow,0);
+        format = cell.format();
+        format.setFontItalic(true);
+        format.setFontPointSize(KGlobalSettings::generalFont().pointSize()+1.0);
+        cell.setFormat(format);
+        cell.firstCursorPosition().insertText(item->text(0));
+        int componentrow = currow;
+        currow++;
+
+        for (int j = 0; j < item->childCount(); j++) {
+            QTreeWidgetItem* actionitem = item->child(j);
+            KShortcutsEditorItem* editoritem = 
+                    dynamic_cast<KShortcutsEditorItem*>(actionitem);
+            table->insertRows(table->rows(),1);
+            QVariant data = editoritem->data(Name,Qt::DisplayRole);
+            table->cellAt(currow, \
1).firstCursorPosition().insertText(data.toString()); +            data = \
editoritem->data(LocalPrimary,Qt::DisplayRole); +            table->cellAt(currow, \
2).firstCursorPosition().insertText(data.value<QKeySequence>().toString()); +         \
data = editoritem->data(LocalAlternate,Qt::DisplayRole); +            \
table->cellAt(currow, \
3).firstCursorPosition().insertText(data.value<QKeySequence>().toString()); +         \
data = editoritem->data(GlobalPrimary,Qt::DisplayRole); +            \
table->cellAt(currow, \
4).firstCursorPosition().insertText(data.value<QKeySequence>().toString()); +
+            KAction* action = editoritem->m_action;
+            cell = table->cellAt(currow, 5);
+            format = cell.format();
+            format.setFontPointSize(KGlobalSettings::generalFont().pointSize()-1.0);
+            cell.setFormat(format);
+            cell.firstCursorPosition().insertText(action->whatsThis());
+            currow++;
+        }
+
+        table->mergeCells(componentrow+1, 0, currow-componentrow, 1);
+    }
+    cursor.endEditBlock();
+    QPrinter printer;
+    QPrintDialog dlg(&printer);
+    if (dlg.exec() == QDialog::Accepted) {
+        doc.print(&printer);
+    }
+}
+
 #include "kshortcutseditor.moc"
Index: kdeui/dialogs/kshortcutsdialog.ui
===================================================================
--- kdeui/dialogs/kshortcutsdialog.ui	(Revision 787925)
+++ kdeui/dialogs/kshortcutsdialog.ui	(Arbeitskopie)
@@ -9,19 +9,24 @@
     <height>549</height>
    </rect>
   </property>
-  <layout class="QVBoxLayout" >
-   <property name="margin" >
-    <number>0</number>
-   </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
+  <layout class="QVBoxLayout" name="verticalLayout" >
    <item>
-    <widget class="KTreeWidgetSearchLineWidget" native="1" name="searchFilter" >
-     <property name="whatsThis" >
-      <string>Search interactively for shortcut names (e.g. Copy) or combination of \
                keys (e.g. Ctrl+C) by typing them here.</string>
-     </property>
-    </widget>
+    <layout class="QHBoxLayout" name="horizontalLayout" >
+     <item>
+      <widget class="KTreeWidgetSearchLineWidget" name="searchFilter" >
+       <property name="whatsThis" >
+        <string>Search interactively for shortcut names (e.g. Copy) or combination \
of keys (e.g. Ctrl+C) by typing them here.</string> +       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="printButton" >
+       <property name="text" >
+        <string>Print</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
    </item>
    <item>
     <widget class="QTreeWidget" name="list" >


["kdeui_shortcuts_print_example.pdf" (application/pdf)]

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

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