25 #include <qpushbutton.h>
29 #include <qtextstream.h>
30 #include <qpopupmenu.h>
32 #include <qapplication.h>
33 #include <qlistview.h>
44 setCaption(tr(
"Qucs Help System"));
47 textBrowser->setMinimumSize(400,200);
48 setCentralWidget(textBrowser);
62 void QucsHelp::setupActions()
64 QToolBar *toolbar =
new QToolBar(
this,
"main_toolbar");
65 QMenuBar *bar = menuBar();
68 const QKeySequence ks = QKeySequence();
71 tr(
"&Quit"), CTRL+Key_Q,
this);
73 tr(
"&Back"), ALT+Key_Left,
this);
75 tr(
"&Forward"), ALT+Key_Right,
this);
77 tr(
"&Home"),CTRL+Key_H,
this);
78 previousAction =
new QAction(QIconSet(QPixmap(
QucsSettings.
BitmapDir +
"previous.png")),tr(
"&Previous"),
81 tr(
"&Next"), ks,
this);
82 viewBrowseDock =
new QAction(tr(
"&Table of Contents"), 0,
this);
83 viewBrowseDock->setToggleAction(
true);
84 viewBrowseDock->setOn(
true);
85 viewBrowseDock->setStatusTip(tr(
"Enables/disables the table of contents"));
86 viewBrowseDock->setWhatsThis(tr(
"Table of Contents\n\nEnables/disables the table of contents"));
88 connect(quitAction,SIGNAL(activated()),qApp,SLOT(quit()));
90 connect(backAction,SIGNAL(activated()),textBrowser,SLOT(backward()));
91 connect(textBrowser,SIGNAL(backwardAvailable(
bool)),backAction,SLOT(setEnabled(
bool)));
93 connect(forwardAction,SIGNAL(activated()),textBrowser,SLOT(forward()));
94 connect(textBrowser,SIGNAL(forwardAvailable(
bool)),forwardAction,SLOT(setEnabled(
bool)));
96 connect(homeAction,SIGNAL(activated()),textBrowser,SLOT(home()));
98 connect(textBrowser,SIGNAL(sourceChanged(
const QString &)),
this,SLOT(slotSourceChanged(
const QString&)));
99 connect(previousAction,SIGNAL(activated()),
this,SLOT(previousLink()));
100 connect(nextAction,SIGNAL(activated()),
this,SLOT(nextLink()));
101 connect(viewBrowseDock, SIGNAL(toggled(
bool)), SLOT(slotToggleSidebar(
bool)));
103 backAction->addTo(toolbar);
104 forwardAction->addTo(toolbar);
105 toolbar->addSeparator();
106 homeAction->addTo(toolbar);
107 previousAction->addTo(toolbar);
108 nextAction->addTo(toolbar);
109 toolbar->addSeparator();
110 quitAction->addTo(toolbar);
112 QPopupMenu *fileMenu =
new QPopupMenu(
this);
113 quitAction->addTo(fileMenu);
115 QPopupMenu *viewMenu =
new QPopupMenu(
this);
116 backAction->addTo(viewMenu);
117 forwardAction->addTo(viewMenu);
118 homeAction->addTo(viewMenu);
119 previousAction->addTo(viewMenu);
120 nextAction->addTo(viewMenu);
121 viewMenu->insertSeparator();
122 viewBrowseDock->addTo(viewMenu);
124 QPopupMenu *helpMenu =
new QPopupMenu(
this);
125 helpMenu->insertItem(tr(
"&About Qt"),qApp,SLOT(aboutQt()));
127 bar->insertItem(tr(
"&File"), fileMenu );
128 bar->insertItem(tr(
"&View"),viewMenu);
129 bar->insertSeparator();
130 bar->insertItem(tr(
"&Help"),helpMenu);
135 void QucsHelp::createSidebar()
137 dock =
new QDockWindow(QDockWindow::InDock,
this);
138 dock->setResizeEnabled(
true);
139 dock->setCloseMode(QDockWindow::Always);
140 connect(dock,SIGNAL(visibilityChanged(
bool)),
this,SLOT(slotToggleSidebarAction(
bool)));
142 chaptersView =
new QListView(dock,
"chapters_view");
143 chaptersView->setRootIsDecorated(
false);
144 chaptersView->addColumn(tr(
"Contents"));
145 chaptersView->setSorting(-1);
146 chaptersView->setSelectionMode(QListView::Single);
148 dock->setWidget(chaptersView);
149 moveDockWindow(dock,QDockWindow::Left);
153 for(
int i=l.count()-1;
i>=0;
i--)
154 chaptersView->insertItem(
new QListViewItem(chaptersView,l[
i],QString::number(i+1)));
156 QListViewItem *curItem =
new QListViewItem(chaptersView,tr(
"Home"),QString::number(0));
157 chaptersView->insertItem(curItem);
158 chaptersView->setSelected(curItem,
true);
160 connect(chaptersView,SIGNAL(selectionChanged()),
this,SLOT(displaySelectedChapter()));
163 void QucsHelp::displaySelectedChapter()
165 if(chaptersView->selectedItem() == 0)
167 uint y = chaptersView->selectedItem()->text(1).toUInt();
168 Q_ASSERT(y < links.count());
170 cachedSelectedText = chaptersView->selectedItem()->text(1);
173 void QucsHelp::slotSourceChanged(
const QString& _str)
177 int hashPos = str.findRev(
'#');
179 str = str.left(hashPos);
181 if(str == currentSource)
185 for(
unsigned int i=0;i < links.count(); i++)
187 if(str.endsWith(links[i]))
190 previousAction->setEnabled(
bool(i!=0));
191 nextAction->setEnabled(
bool(i+1 != links.count()));
192 QString temp = cachedSelectedText;
193 if(chaptersView->selectedItem())
194 temp = chaptersView->selectedItem()->text(1);
195 if(temp.toUInt() !=
i)
197 QListViewItem *item = chaptersView->findItem(QString::number(i),1);
200 chaptersView->blockSignals(
true);
201 chaptersView->setSelected(item,
true);
202 chaptersView->blockSignals(
false);
213 qDebug(
"QucsHelp::slotSourceChanged(): Link mismatch \n Link: %s",str.ascii());
220 void QucsHelp::previousLink()
227 void QucsHelp::nextLink()
230 if(currentIndex >= links.count())
231 currentIndex = links.count();
235 void QucsHelp::slotToggleSidebar(
bool b)
240 void QucsHelp::slotToggleSidebarAction(
bool b)
242 viewBrowseDock->blockSignals(
true);
243 viewBrowseDock->setOn(b);
244 viewBrowseDock->blockSignals(
false);