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

List:       kde-commits
Subject:    playground/graphics/UNNAMED_READER
From:       Stefan Kebekus <kebekus () kde ! org>
Date:       2006-12-13 7:10:47
Message-ID: 1165993847.502958.7018.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 613023 by kebekus:

added proper document titles to the tabBar, recent files to the taskbar


 M  +6 -0      UNNAMED_READER/UNNAMED_READERui.rc  
 M  +72 -20    UNNAMED_READER/autoHideTabWidget.cpp  
 M  +18 -1     UNNAMED_READER/autoHideTabWidget.h  
 M  +33 -24    UNNAMED_READER/mainWindow.cpp  
 M  +6 -3      corelibrary/CMakeLists.txt  
 M  +53 -1     corelibrary/readerWidget.cpp  
 M  +55 -2     corelibrary/readerWidget.h  


--- trunk/playground/graphics/UNNAMED_READER/UNNAMED_READER/UNNAMED_READERui.rc \
#613022:613023 @@ -2,4 +2,10 @@
 <kpartgui name="UNNAMED_READER" version="1">
 <MenuBar>
 </MenuBar>
+
+<ToolBar noMerge="1" name="mainToolBar" >
+ <text>Main Toolbar</text>
+ <Action name="file_open_recent" />
+</ToolBar>
+
 </kpartgui>
--- trunk/playground/graphics/UNNAMED_READER/UNNAMED_READER/autoHideTabWidget.cpp \
#613022:613023 @@ -23,6 +23,7 @@
 
 #include <kiconloader.h>
 #include <klocale.h>
+#include <kstandarddirs.h>
 #include <QIcon>
 #include <QTabBar>
 #include <QToolButton>
@@ -36,48 +37,47 @@
   : KTabWidget(parent)
 {
   tabBar()->setWhatsThis(i18n( "This bar contains the list of currently open tabs. \
                Click on a tab to make it "
-			       "active. You can use keyboard shortcuts to "
-			       "navigate through tabs. The text on the tab shows the name of the document \
                "
-			       "currently open in it. Put your mouse over the tab too see the full name \
                in"
-			       "case it was truncated to fit the tab size." ) );
+			       "active. Move the mouse pointer to the tab too see the full document name \
and URL." ) );  
-#warning "Toggle toolbar crashes"
-
+  // Create "Close Tab" corner widget
   QToolButton *rightWidget = new QToolButton( this );
   connect( rightWidget, SIGNAL(clicked()), this, SLOT(deleteCurrentTab()));
-  rightWidget->setIcon( SmallIconSet( "tab_remove" ) );
+  rightWidget->setIcon( SmallIconSet("tab_remove") );
   rightWidget->adjustSize();
   rightWidget->setToolTip( i18n("<qt>Close the current tab</qt>"));
   rightWidget->setWhatsThis( i18n("<qt>Close the current tab</qt>"));
   setCornerWidget(rightWidget);
-
+  
   setAutomaticResizeTabs( true );
   setTabReorderingEnabled( true );
 }
-
   
+  
 autoHideTabWidget::~autoHideTabWidget()
 {
 }
-
-
-void autoHideTabWidget::tabInserted(int)
+  
+  
+void autoHideTabWidget::tabInserted(int i)
 {
   kDebug(UNNAMED_READER_DEBUG, shell) << "autoHideTabWidget::tabInserted(...)" << \
endl;  
-#warning if a reader widget is added readerWidget, then extract information about \
                title
-  tabBar()->setTabToolTip (1, i18n("FileName"));
+  QWidget *wdg = widget(i);
+  if (wdg == 0)
+    return;
 
-  tabRemoved(0);
+  if (wdg->inherits("UNNAMED_READER::readerWidget")) {
+    setTabNameAndToolTip((readerWidget *)wdg);
+    connect((readerWidget *)wdg, SIGNAL(documentFullyLoaded(readerWidget *)), this, \
SLOT(setTabNameAndToolTip(readerWidget *))); +  }
+
+  setTabBarShown();
 }
 
 
-void autoHideTabWidget::tabRemoved(int index)
+void autoHideTabWidget::tabRemoved(int)
 {
-  if (count() < 2)
-    tabBar()->hide();
-  else
-    tabBar()->show();
+  setTabBarShown();
 }
 
 
@@ -96,6 +96,58 @@
 }
 
 
+void autoHideTabWidget::setTabNameAndToolTip(readerWidget *wdg)
+{
+  kDebug(UNNAMED_READER_DEBUG, shell) << "autoHideTabWidget::setTabNameAndToolTip()" \
<< endl; +  
+  if (wdg == 0) {
+    kError(shell) << "autoHideTabWidget::setTabNameAndToolTip() called with 0 \
argument" << endl; +    return;
+  }
+
+  int i = indexOf(wdg);
+  if (i < 0) {
+    kError(shell) << "autoHideTabWidget::setTabNameAndToolTip() called with widget \
that is not open in the tabWidget" << endl; +    return;
+  }
+
+
+  // Set text in the tab
+  KUrl url = wdg->document();
+  if (url.isLocalFile() && url.path().startsWith(KStandardDirs::locateLocal("tmp", \
QString::null)))  +    tabBar()->setTabText(i, i18n("Temporary File"));
+  else
+    if (url.fileName().isEmpty())
+      tabBar()->setTabText(i, url.pathOrUrl());
+    else
+      tabBar()->setTabText(i, url.fileName());
+  
+
+  // Set ToolTip text
+  QString title = wdg->documentTitle();
+  if (title.isEmpty())
+    title = QString("<qt>%1</qt>").arg(url.pathOrUrl());
+  else {
+    QString fname;
+    if (url.isLocalFile() && url.path().startsWith(KStandardDirs::locateLocal("tmp", \
QString::null)))  +      fname = i18n("Temporary File");
+    else
+      fname = url.pathOrUrl();
+    title = QString("<qt><strong>%1</strong><br>%2</qt>").arg(title).arg(fname);
+  }
+  tabBar()->setTabToolTip(i, title);
+}
+
+
+void autoHideTabWidget::setTabBarShown()
+{
+  if (count() < 2)
+    tabBar()->hide();
+  else
+    tabBar()->show();
+}
+
+
 } // end: namespace UNNAMED_READER
 
 
--- trunk/playground/graphics/UNNAMED_READER/UNNAMED_READER/autoHideTabWidget.h \
#613022:613023 @@ -24,8 +24,12 @@
 #include <ktabwidget.h>
 
 
+
 namespace UNNAMED_READER {
 
+class readerWidget;
+
+
 /**
  * @short UNNAMED_READER widget for tabbed view
  *
@@ -71,7 +75,20 @@
    * Deletes the current tab. When the tab contains a readerWidget,
    * use methods from the readerWidget to ask first.
    */
-   void deleteCurrentTab();
+  void deleteCurrentTab();
+ 
+  /**
+   * If the readerWidget is opened in a tab, extract title and URL
+   * information to set the tab text and the toolTip
+   */
+  void setTabNameAndToolTip(readerWidget *wdg);
+
+ private:
+ /**
+  * This method will show the tabBar if at least two tabs are there,
+  * and hide it otherwise.
+  */
+  void setTabBarShown();
 };
 
 
--- trunk/playground/graphics/UNNAMED_READER/UNNAMED_READER/mainWindow.cpp \
#613022:613023 @@ -100,13 +100,17 @@
 
 void mainWindow::setupActions()
 {
+  kDebug(UNNAMED_READER_DEBUG, shell) << "mainWindow::setupAction()" << endl;
+
   KStdAction::open(this, SLOT(open()), actionCollection());
 
   // Open recent files
-  action_openRecent = KStdAction::openRecent( this, SLOT(openUrl(KUrl)), \
actionCollection() ); +  action_openRecent = KStdAction::openRecent(this, \
SLOT(openUrl(KUrl)), actionCollection()); +  \
action_openRecent->setToolBarMode(KRecentFilesAction::MenuMode); // Make a menu, not \
a combobox +  action_openRecent->setToolButtonPopupMode(QToolButton::DelayedPopup); \
// Don't show the menu immediately +  connect(action_openRecent, SIGNAL(triggered()), \
this, SLOT(open()));  action_openRecent->setWhatsThis( i18n( \
"<qt><strong>Click</strong> to open a file or <strong>Click and hold</strong> to \
select a recent file" ) );  action_openRecent->setToolTip( i18n( \
"<qt><strong>Click</strong> to open a file or <strong>Click and hold</strong> to \
                select a recent file" ) );
-#warning TODO: use trigger slot of the action
 
   KStdAction::quit(kapp, SLOT(quit()), actionCollection());
 
@@ -127,6 +131,7 @@
     return;
   }
 
+
   // Before opening a new tab, go through the list of documents that
   // are already open, and check if the url points to one of these. If
   // yes, bring that document to the front, and go to the reference
@@ -135,39 +140,43 @@
   docurl.setRef(QString::null);
   QList<readerWidget *> readers = findChildren<readerWidget *>();
   for(int i=0; i<readers.count(); i++) {
-    if (readers.at(i)->document() == docurl) {
+    readerWidget *wdg = readers.at(i);
+    if (wdg == 0)
+      continue;
+    if (wdg->document() == docurl) {
       workspace->setCurrentWidget(readers.at(i));
       // Bring the window to the front, so the user sees where we're going.
       activateWindow();
       raise();
-
-#warning TODO go to reference!
-
+      wdg->goTo(url.ref());
       return;
     }
   }
   
-  readerWidget *label = new readerWidget(this, url);
 
-#warning TODO: set success to true or false, depending on whether the document could \
                be opened or not.
-  bool success = true;
+  // The document is not yet open. Construct a new reader widget that
+  // shows the document
+  bool success;
+  readerWidget *reader = new readerWidget(this, url, &success);
+  if (success == false) {
+    // If opening the document failed, don't go on. 
+    delete reader;
+    return;
+  }
+  
 
-  if (success) {
-    // Open a new tab that contains the readerWidget.
-#warning TODO: Check Qt documentation for the QTabWidget to check how to avoid \
                flicker
-    workspace->addTab(label, url.fileName());
-    workspace->setCurrentWidget(label);
+  // Open a new tab that contains the readerWidget. The
+  // autoHideTabWidget will automatically extract the document title
+  // to set up the tooltip, etc.
+  workspace->addTab(reader, url.fileName());
+  workspace->setCurrentWidget(reader);
 
-    // Add the file to the list of recently used files if it is a
-    // local, but not a temporary file.
-    if (url.isLocalFile() && \
                !url.path().startsWith(KStandardDirs::locateLocal("tmp", \
                QString::null))) {
-      action_openRecent->addUrl(url);
-      writeSettings();    // Save the modified list, so other
-			  // instances of the UNNAMED_READER have can
-			  // use it immediately
-    }
-  } else { // If no success
-    delete workspace;
+  
+  // Add the document URL to the list of recently used files if it is
+  // a local, but not a temporary file.
+  if (url.isLocalFile() && !url.path().startsWith(KStandardDirs::locateLocal("tmp", \
QString::null))) { +    action_openRecent->addUrl(url);
+    writeSettings();    // Save the modified list, so other instances of the \
UNNAMED_READER have can use it immediately  }
 }
 
--- trunk/playground/graphics/UNNAMED_READER/corelibrary/CMakeLists.txt \
#613022:613023 @@ -9,15 +9,18 @@
 kde4_automoc(${UNNAMED_READERcore_LIB_SRCS})
 
 kde4_add_ui_files(UNNAMED_READERcore_LIB_SRCS
-   readerWidget.ui )
+	readerWidget.ui )
 
-qt4_add_resources(UNNAMED_READERcore_LIB_SRCS readerWidget.qrc)
+qt4_add_resources(UNNAMED_READERcore_LIB_SRCS
+	readerWidget.qrc )
 
 #kde4_add_kcfg_files(UNNAMED_READERcore_LIB_SRCS kvsprefs.kcfgc )
 
 kde4_add_library(UNNAMED_READERcore SHARED ${UNNAMED_READERcore_LIB_SRCS})
 
-target_link_libraries(UNNAMED_READERcore ${KDE4_KDECORE_LIBS} )
+target_link_libraries(UNNAMED_READERcore 
+	${KDE4_KDECORE_LIBS}
+	${KDE4_KDEUI_LIBS} )
 
 set_target_properties(UNNAMED_READERcore PROPERTIES VERSION 1.0.0 SOVERSION 1 )
 
--- trunk/playground/graphics/UNNAMED_READER/corelibrary/readerWidget.cpp \
#613022:613023 @@ -21,15 +21,19 @@
 #include "ui_readerWidget.h"
 #include "UNNAMED_READER_debug.h"
 
+#include "kmessagebox.h"
 
 namespace UNNAMED_READER {
 
 #define UNNAMED_READER_DEBUG 1
 
 
-readerWidget::readerWidget(QWidget *parent, KUrl url) 
+readerWidget::readerWidget(QWidget *parent, KUrl url, bool *ok) 
   : QWidget(parent)
 {
+  if (ok != 0)
+    *ok = false;
+
   documentURL = url;
   documentURL.setRef(QString::null);
 
@@ -37,6 +41,20 @@
 
   dlg = new Ui_readerWidget();
   dlg->setupUi(this);
+
+#warning TODO: open document
+
+  goTo(url.ref());
+
+  if (ok != 0)
+    *ok = true;
+
+  // Fake loading of the document
+  connect(&fakeTimer, SIGNAL(timeout()), this, SLOT(fakeFinishedLoading()));
+  fakeTimer.setSingleShot(true);
+  fakeTimer.start(1000*(qrand()%5)); // simulate loading for some seconds
+
+  return;
 }
 
  
@@ -45,6 +63,19 @@
 }
 
 
+QString readerWidget::documentTitle() const
+{
+  kError(UNNAMED_READER_DEBUG, shell) << "readerWidget::documentTitle() is not \
implemented yet" << endl; +
+#warning TODO: Implement this
+
+  if (isFullyLoaded())
+    return QString("A treatise of human understanding");
+  else
+    return QString::null;
+}
+
+
 void readerWidget::askToClose(void)
 {
   kDebug(UNNAMED_READER_DEBUG, shell) << "readerWidget::askToClose()" << endl;
@@ -54,8 +85,29 @@
   deleteLater();
 }
 
+
+void readerWidget::goTo(QString reference)
+{
+  kDebug(UNNAMED_READER_DEBUG, shell) << "readerWidget::goTo(" << reference << ")" \
<< endl; +
+  if (reference.isEmpty())
+    return;
   
+#warning TODO: Check form of reference
+  
+#warning TODO: Not implemented yet
+  KMessageBox::error(this, i18n("<qt>UNNAMED reader cannot go to the reference \
<strong>%1</strong> " +				"in the document %2, because this feature is not yet \
implemented.</qt>", +				reference, documentURL.pathOrUrl()));
+}
+  
 
+void readerWidget::fakeFinishedLoading()
+{
+  emit documentFullyLoaded(this);
+}
+
+
 } // end: namespace UNNAMED_READER
 
 #include "readerWidget.moc"
--- trunk/playground/graphics/UNNAMED_READER/corelibrary/readerWidget.h \
#613022:613023 @@ -22,6 +22,7 @@
 #define _READERWIDGET_H_
 
 #include <KUrl>
+#include <QTimer>
 #include <QWidget>
 
 class Ui_readerWidget;
@@ -54,12 +55,21 @@
   /**
    * Default Constructor
    *
+   * This method constructs a new reader widget that will display the
+   * document named in the URL. If the document cannot be opened, a
+   * dialog opens, and the variable ok will be set to 'false'.
+   *
    * @par parent the usual parent widget, or 0
    *
    * @par url a URL pointing to the document that this widget will
-   * show
+   * show. If the URL has a reference part, the constructor will use
+   * the method goTo() to make sure that the document is opened at the
+   * place that the reference points to.
+   *
+   * @par ok either zero, or a pointer to a bool which is set to
+   * 'true' on success, and 'false' otherwise.
    */
-  readerWidget(QWidget *parent, KUrl url);
+  readerWidget(QWidget *parent, KUrl url, bool *ok=0);
   
   /**
    * Default Destructor
@@ -72,6 +82,14 @@
   KUrl document() const {return documentURL;}
 
   /**
+   * Returns the title of the document
+   *
+   * Returns the title of the document, or an empty string if the
+   * document does not have a title, or if the title is unknown.
+   */
+  QString documentTitle() const;
+
+  /**
    * Schedules deletion of the widget
    *
    * If the document has been modified, ask the user if the document
@@ -80,15 +98,50 @@
    */
   void askToClose(void);
 
+  /**
+   * Moves the view to show the reference
+   *
+   * Moves the viewport, so that the reference is visible, and marks
+   * it visually. If the string cannot be parsed, or if the reference
+   * does not exist, an error dialog will be shown to the user. If the
+   * document cannot be rendered yet, the reference is shown as soon
+   * as rendering is possible.
+   *
+   * @par reference a string of type "page:number", "anchor:name" or
+   * "src:number:filename", as explained in the user documentation,
+   * section "The reference part of the URL". If the reference is
+   * empty, the method will return quietly.
+   */
+  void goTo(QString reference);
+
+  /**
+   * Returns true if the document is fully loaded
+   */
+  bool isFullyLoaded() const {return !fakeTimer.isActive();}
+
+ signals:
+  /**
+   * This signal is emitted when the document is fully loaded, and all
+   * information is available
+   */
+  void documentFullyLoaded(readerWidget *this_widget);
+
  protected:
   /** Pointer to the class created by the Qt designer this sets up the
       GUI */
   Ui_readerWidget *dlg;
 
+ private slots:
+  /* This method fakes that the document has been loaded */
+  void fakeFinishedLoading();
+
  private:
   /* A copy of the URL given in the constructor, with the reference
      part set to QString::null */
   KUrl documentURL;
+
+  /* Time to fake loading of document */
+  QTimer fakeTimer;
 };
 
 


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

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