Browse Source

Implement help on right-click in the Program Options dialog.

git-svn-id: file:///var/svn/tigccpp/trunk@523 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 18 years ago
parent
commit
0acae66230
5 changed files with 50 additions and 1 deletions
  1. 20 0
      ktigcc/ktigcc.cpp
  2. 3 0
      ktigcc/ktigcc.h
  3. 1 1
      ktigcc/mainform.ui.h
  4. 1 0
      ktigcc/programoptions.ui
  5. 25 0
      ktigcc/programoptions.ui.h

+ 20 - 0
ktigcc/ktigcc.cpp

@@ -187,3 +187,23 @@ void force_qt_assistant_page(int n)
   }
   fclose(f);
 }
+
+const char *lookup_doc_keyword(const char *keyword)
+{
+  static char filename[256];
+  memset(filename,0,256);
+  char fname[strlen(tigcc_base)+27];
+  sprintf(fname,"%s/doc/html/qt-assistant.adp",tigcc_base);
+  FILE *f=fopen(fname,"r+b");
+  if (!f) return "";
+  char buffer[32768], keywbuf[32768];
+  while (!feof(f)) {
+    if (!fgets(buffer,32768,f)) {fclose(f); return "";}
+    memset(keywbuf,0,32768);
+    if (sscanf(buffer,"<keyword ref=\"%255[^\"]\">%32767[^<]</keyword>",filename,keywbuf)<2)
+      continue;
+    if (!strcmp(keywbuf,keyword)) {fclose(f); return filename;}
+  }
+  fclose(f);
+  return "";
+}

+ 3 - 0
ktigcc/ktigcc.h

@@ -22,6 +22,7 @@
 #include <cstddef>
 #include <kconfig.h>
 #include <kaboutdata.h>
+class QAssistantClient;
 
 extern const char *tigcc_base;
 extern const char *quill_drv;
@@ -31,6 +32,8 @@ extern char tempdir[];
 extern void write_temp_file(const char *filename, const char *data, const size_t len);
 extern void delete_temp_file(const char *filename);
 extern void force_qt_assistant_page(int n);
+const char *lookup_doc_keyword(const char *keyword);
 extern KConfig *pconfig;
 extern KAboutData *pabout;
 extern const char *parg;
+extern QAssistantClient *assistant;

+ 1 - 1
ktigcc/mainform.ui.h

@@ -216,7 +216,7 @@ static QLabel *rightStatusLabel;
 static KParts::Factory* factory;
 static KHelpMenu *khelpmenu;
 static QPopupMenu *te_popup;
-static QAssistantClient *assistant;
+QAssistantClient *assistant;
 static int fileCount=0, hFileCount=0, cFileCount=0, sFileCount=0, asmFileCount=0, qllFileCount=0, oFileCount=0, aFileCount=0, txtFileCount=0, othFileCount=0;
 tprSettings settings; //static is turned off here so ProjectOptions can access it.
 tprLibOpts libopts; //static is turned off here so ProgramOptions can access it.

+ 1 - 0
ktigcc/programoptions.ui

@@ -1686,6 +1686,7 @@
 <functions>
     <function specifier="non virtual">ImportSettings()</function>
     <function specifier="non virtual">ExportSettings()</function>
+    <function access="protected">mousePressEvent( QMouseEvent * e )</function>
 </functions>
 <pixmapinproject/>
 <layoutdefaults spacing="6" margin="11"/>

+ 25 - 0
ktigcc/programoptions.ui.h

@@ -31,6 +31,12 @@
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
 */
 
+#include <qapp.h>
+#include <qevent.h>
+#include <qeventloop.h>
+#include <qtooltip.h>
+#include <qassistantclient.h>
+#include "ktigcc.h"
 #include "tpr.h"
 
 extern tprLibOpts libopts;
@@ -294,3 +300,22 @@ void ProgramOptions::RelocSettings_toggled(bool on_unused)
     inEvent=FALSE;
   }
 }
+
+
+void ProgramOptions::mousePressEvent( QMouseEvent * e )
+{
+  if (e->button()==Qt::RightButton) {
+    QWidget *widgetUnderCursor=childAt(e->pos());
+    if (!widgetUnderCursor) return;
+    QString toolTip=QToolTip::textFor(widgetUnderCursor, widgetUnderCursor->mapFromParent(e->pos()));
+    if (toolTip.isEmpty()) return;
+    QString docFile=lookup_doc_keyword(toolTip);
+    if (docFile.isEmpty()) return;
+    force_qt_assistant_page(1);
+    assistant->openAssistant();
+    // wait for it to actually open
+    while (!assistant->isOpen())
+      QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput,1000);
+    assistant->showPage(QString(tigcc_base)+QString("/doc/html/")+docFile);
+  }
+}