VirtualBox

Ignore:
Timestamp:
Oct 15, 2020 9:26:34 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9831. Linking and using qthelp stuff only on Linux.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp

    r86573 r86581  
    13721372    const QString strSuffix = "pdf";
    13731373#elif defined(VBOX_WS_X11)
    1374 # if defined(VBOX_OSE) || !defined(VBOX_WITH_KCHMVIEWER)
     1374    //# if defined(VBOX_OSE) || !defined(VBOX_WITH_KCHMVIEWER)
    13751375    const QString strName = "UserManual";
    1376     const QString strSuffix = "pdf";
    1377 # else
    1378     const QString strName = "VirtualBox";
    1379     const QString strSuffix = "chm";
    1380 # endif
     1376    const QString strSuffix = "qhc";
     1377    //# else
     1378    // const QString strName = "VirtualBox";
     1379    // const QString strSuffix = "chm";
     1380    //# endif
    13811381#endif
    13821382
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r86341 r86581  
    32033203    QProcess::startDetached(QString(szViewerPath) + "/kchmviewer", QStringList(strLocation));
    32043204# else /* #if !defined(VBOX_OSE) && defined(VBOX_WITH_KCHMVIEWER) */
     3205    /* instead of viewing the pdf manual show qtHelp one. This is soon to be default in all platforms. */
    32053206    showHelpBrowser(strLocation);
    32063207# endif /* #if defined(VBOX_OSE) || !defined(VBOX_WITH_KCHMVIEWER) */
     
    33933394}
    33943395
    3395 void UIMessageCenter::showHelpBrowser(const QString strHelpFileLocation, QWidget *pParent /* = 0 */)
    3396 {
    3397     Q_UNUSED(strHelpFileLocation);
     3396void UIMessageCenter::showHelpBrowser(const QString strHelpFilePath, QWidget *pParent /* = 0 */)
     3397{
    33983398    QWidget *pDialogParent = windowManager().realParentWindow(pParent ? pParent : windowManager().mainWindowShown());
    33993399    AssertReturnVoid(pDialogParent);
     
    34013401
    34023402    QIManagerDialog *pHelpBrowserDialog;
    3403     UIHelpBrowserDialogFactory dialogFactory;
     3403    UIHelpBrowserDialogFactory dialogFactory(strHelpFilePath);
    34043404
    34053405    dialogFactory.prepare(pHelpBrowserDialog);
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r86341 r86581  
    598598                       const QString &strAutoConfirmId) const;
    599599
    600     void showHelpBrowser(const QString strHelpFileLocation, QWidget *pParent = 0);
     600    void showHelpBrowser(const QString strHelpFilePath, QWidget *pParent = 0);
    601601
    602602    /** Holds the list of shown warnings. */
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserDialog.cpp

    r86341 r86581  
    4444*********************************************************************************************************************************/
    4545
    46 UIHelpBrowserDialogFactory::UIHelpBrowserDialogFactory()
     46UIHelpBrowserDialogFactory::UIHelpBrowserDialogFactory(const QString &strHelpFilePath /*  = QString() */)
     47    :m_strHelpFilePath(strHelpFilePath)
    4748{
    4849}
     
    5051void UIHelpBrowserDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
    5152{
    52     pDialog = new UIHelpBrowserDialog(pCenterWidget);
     53    pDialog = new UIHelpBrowserDialog(pCenterWidget, m_strHelpFilePath);
    5354}
    5455
     
    5859*********************************************************************************************************************************/
    5960
    60 UIHelpBrowserDialog::UIHelpBrowserDialog(QWidget *pCenterWidget)
     61UIHelpBrowserDialog::UIHelpBrowserDialog(QWidget *pCenterWidget, const QString &strHelpFilePath)
    6162    : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
     63    , m_strHelpFilePath(strHelpFilePath)
    6264{
    6365}
     
    8082{
    8183    /* Create widget: */
    82     UIHelpBrowserWidget *pWidget = new UIHelpBrowserWidget(EmbedTo_Dialog, true /* show toolbar */, this);
     84    UIHelpBrowserWidget *pWidget = 0;
     85
     86#ifdef VBOX_WS_X11
     87    pWidget = new UIHelpBrowserWidget(EmbedTo_Dialog, m_strHelpFilePath, true /* show toolbar */, this);
     88#endif
     89
    8390    if (pWidget)
    8491    {
     
    105112void UIHelpBrowserDialog::loadSettings()
    106113{
    107     /* Invent default window geometry: */
    108     const QRect availableGeo = gpDesktop->availableGeometry(this);
    109     int iDefaultWidth = availableGeo.width() / 2;
    110     int iDefaultHeight = availableGeo.height() * 3 / 4;
    111     /* Try obtain the default width of the current logviewer: */
    112     const UIHelpBrowserWidget *pWidget = qobject_cast<const UIHelpBrowserWidget*>(widget());
    113     if (pWidget)
    114     {
    115         const int iWidth = pWidget->defaultLogPageWidth();
    116         if (iWidth != 0)
    117             iDefaultWidth = iWidth;
    118     }
    119     QRect defaultGeo(0, 0, iDefaultWidth, iDefaultHeight);
    120 
    121     /* Load geometry from extradata: */
    122     const QRect geo = gEDataManager->logWindowGeometry(this, centerWidget(), defaultGeo);
    123     LogRel2(("GUI: UIHelpBrowserDialog: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
    124              geo.x(), geo.y(), geo.width(), geo.height()));
    125     restoreGeometry(geo);
    126114}
    127115
    128116void UIHelpBrowserDialog::saveSettings()
    129117{
    130     /* Save geometry to extradata: */
    131     const QRect geo = currentGeometry();
    132     LogRel2(("GUI: UIHelpBrowserDialog: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
    133              geo.x(), geo.y(), geo.width(), geo.height()));
    134     gEDataManager->setLogWindowGeometry(geo, isCurrentlyMaximized());
    135118}
    136119
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserDialog.h

    r86341 r86581  
    4545public:
    4646
    47     UIHelpBrowserDialogFactory();
     47    UIHelpBrowserDialogFactory(const QString &strHelpFilePath = QString());
    4848
    4949protected:
     
    5353    virtual void create(QIManagerDialog *&pDialog, QWidget *pCenterWidget) /* override */;
    5454
     55private:
     56
     57    QString m_strHelpFilePath;
    5558};
    5659
     
    6366public:
    6467
    65     UIHelpBrowserDialog(QWidget *pCenterWidget);
     68    UIHelpBrowserDialog(QWidget *pCenterWidget, const QString &strHelpFilePath);
    6669
    6770protected:
     
    101104private:
    102105
     106    QString m_strHelpFilePath;
    103107};
    104108
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp

    r86341 r86581  
    2020#include <QDir>
    2121#include <QFont>
     22#ifdef VBOX_WS_X11
     23 #include <QtHelp/QHelpEngine>
     24 #include <QtHelp/QHelpContentWidget>
     25#endif
    2226#include <QMenu>
    23 #include <QPainter>
    24 #include <QPlainTextEdit>
    2527#include <QScrollBar>
    2628#include <QStyle>
    27 #include <QTextBlock>
    28 #include <QVBoxLayout>
     29#include <QTextBrowser>
     30#include <QHBoxLayout>
    2931#ifdef RT_OS_SOLARIS
    3032# include <QFontDatabase>
     
    5052#include "CSystemProperties.h"
    5153
     54class UIHelpBrowserViewer : public QTextBrowser
     55{
     56    Q_OBJECT;
     57
     58public:
     59
     60    UIHelpBrowserViewer(const QHelpEngine *pHelpEngine, QWidget *pParent = 0);
     61    virtual QVariant loadResource(int type, const QUrl &name) /* override */;
     62
     63private:
     64
     65#ifdef VBOX_WS_X11
     66    const QHelpEngine* m_pHelpEngine;
     67#endif
     68};
     69
     70UIHelpBrowserViewer::UIHelpBrowserViewer(const QHelpEngine *pHelpEngine, QWidget *pParent /* = 0 */)
     71    :QTextBrowser(pParent)
     72#ifdef VBOX_WS_X11
     73    , m_pHelpEngine(pHelpEngine)
     74#endif
     75{
     76}
     77
     78QVariant UIHelpBrowserViewer::loadResource(int type, const QUrl &name)
     79{
     80#ifdef VBOX_WS_X11
     81    if (name.scheme() == "qthelp" && m_pHelpEngine)
     82        return QVariant(m_pHelpEngine->fileData(name));
     83    else
     84        return QTextBrowser::loadResource(type, name);
     85#else
     86    return QTextBrowser::loadResource(type, name);
     87#endif
     88}
     89
     90
    5291UIHelpBrowserWidget::UIHelpBrowserWidget(EmbedTo enmEmbedding,
     92                                         const QString &strHelpFilePath,
    5393                                         bool fShowToolbar /* = true */,
    5494                                         QWidget *pParent /* = 0 */)
     
    5797    , m_fShowToolbar(fShowToolbar)
    5898    , m_fIsPolished(false)
     99    , m_pMainLayout(0)
    59100    , m_pTabWidget(0)
    60     , m_pSearchPanel(0)
    61     , m_pFilterPanel(0)
    62     , m_pBookmarksPanel(0)
    63     , m_pOptionsPanel(0)
    64     , m_pMainLayout(0)
    65101    , m_pToolBar(0)
    66     , m_bShowLineNumbers(true)
    67     , m_bWrapLines(false)
    68     , m_font(QFontDatabase::systemFont(QFontDatabase::FixedFont))
     102    , m_strHelpFilePath(strHelpFilePath)
     103#ifdef VBOX_WS_X11
     104    , m_pHelpEngine(0)
     105#endif
     106    , m_pTextBrowser(0)
    69107{
    70108    /* Prepare VM Log-Viewer: */
    71109    prepare();
    72     restorePanelVisibility();
    73110}
    74111
     
    79116}
    80117
    81 int UIHelpBrowserWidget::defaultLogPageWidth() const
    82 {
    83     if (!m_pTabWidget)
    84         return 0;
    85 
    86     QWidget *pContainer = m_pTabWidget->currentWidget();
    87     if (!pContainer)
    88         return 0;
    89 
    90     QPlainTextEdit *pBrowser = pContainer->findChild<QPlainTextEdit*>();
    91     if (!pBrowser)
    92         return 0;
    93     /* Compute a width for 132 characters plus scrollbar and frame width: */
    94     int iDefaultWidth = pBrowser->fontMetrics().width(QChar('x')) * 132 +
    95                         pBrowser->verticalScrollBar()->width() +
    96                         pBrowser->frameWidth() * 2;
    97 
    98     return iDefaultWidth;
    99 }
    100 
    101118QMenu *UIHelpBrowserWidget::menu() const
    102119{
     
    104121}
    105122
    106 QFont UIHelpBrowserWidget::currentFont() const
    107 {
    108     const UIVMLogPage* logPage = currentLogPage();
    109     if (!logPage)
    110         return QFont();
    111     return logPage->currentFont();
    112 }
    113123
    114124bool UIHelpBrowserWidget::shouldBeMaximized() const
     
    117127}
    118128
    119 void UIHelpBrowserWidget::sltDeleteBookmark(int index)
    120 {
    121     UIVMLogPage* logPage = currentLogPage();
    122     if (!logPage)
    123         return;
    124     logPage->deleteBookmark(index);
    125     if (m_pBookmarksPanel)
    126         m_pBookmarksPanel->updateBookmarkList(logPage->bookmarkVector());
    127 }
    128 
    129 void UIHelpBrowserWidget::sltDeleteAllBookmarks()
    130 {
    131     UIVMLogPage* logPage = currentLogPage();
    132     if (!logPage)
    133         return;
    134     logPage->deleteAllBookmarks();
    135 
    136     if (m_pBookmarksPanel)
    137         m_pBookmarksPanel->updateBookmarkList(logPage->bookmarkVector());
    138 }
    139 
    140 void UIHelpBrowserWidget::sltUpdateBookmarkPanel()
    141 {
    142     if (!currentLogPage() || !m_pBookmarksPanel)
    143         return;
    144     m_pBookmarksPanel->updateBookmarkList(currentLogPage()->bookmarkVector());
    145 }
    146 
    147 void UIHelpBrowserWidget::gotoBookmark(int bookmarkIndex)
    148 {
    149     if (!currentLogPage())
    150         return;
    151     currentLogPage()->scrollToBookmark(bookmarkIndex);
    152 }
    153 
    154 void UIHelpBrowserWidget::sltPanelActionToggled(bool fChecked)
    155 {
    156     QAction *pSenderAction = qobject_cast<QAction*>(sender());
    157     if (!pSenderAction)
    158         return;
    159     UIDialogPanel* pPanel = 0;
    160     /* Look for the sender() within the m_panelActionMap's values: */
    161     for (QMap<UIDialogPanel*, QAction*>::const_iterator iterator = m_panelActionMap.begin();
    162         iterator != m_panelActionMap.end(); ++iterator)
     129void UIHelpBrowserWidget::prepare()
     130{
     131    loadOptions();
     132
     133    prepareActions();
     134    prepareWidgets();
     135
     136
     137    retranslateUi();
     138}
     139
     140void UIHelpBrowserWidget::prepareActions()
     141{
     142
     143}
     144
     145void UIHelpBrowserWidget::prepareWidgets()
     146{
     147    /* Create main layout: */
     148    m_pMainLayout = new QHBoxLayout(this);
     149    AssertReturnVoid(m_pMainLayout);
     150#ifdef VBOX_WS_X11
     151    m_pHelpEngine = new QHelpEngine(m_strHelpFilePath, this);
     152    connect(m_pHelpEngine, &QHelpEngine::setupFinished,
     153            this, &UIHelpBrowserWidget::sltHandleHelpEngineSetupFinished);
     154
     155    // m_pTabWidget = new QITabWidget;
     156    // m_pMainLayout->addWidget(m_pTabWidget);
     157    m_pTextBrowser = new UIHelpBrowserViewer(m_pHelpEngine);
     158    AssertReturnVoid(m_pTextBrowser);
     159    m_pMainLayout->addWidget(m_pTextBrowser);
     160
     161    if (QFile(m_strHelpFilePath).exists() && m_pHelpEngine)
    163162    {
    164         if (iterator.value() == pSenderAction)
    165             pPanel = iterator.key();
     163        bool fSetupResult = m_pHelpEngine->setupData();
     164        //m_pHelpEngine->registerDocumentation(m_strHelpFilePath));
     165        printf("setup data %d %s\n", fSetupResult, qPrintable(m_strHelpFilePath));
    166166    }
    167     if (!pPanel)
    168         return;
    169     if (fChecked)
    170         showPanel(pPanel);
    171     else
    172         hidePanel(pPanel);
    173 }
    174 
    175 void UIHelpBrowserWidget::sltSearchResultHighLigting()
    176 {
    177     if (!m_pSearchPanel || !currentLogPage())
    178         return;
    179     currentLogPage()->setScrollBarMarkingsVector(m_pSearchPanel->matchLocationVector());
    180 }
    181 
    182 void UIHelpBrowserWidget::sltHandleSearchUpdated()
    183 {
    184     if (!m_pSearchPanel || !currentLogPage())
    185         return;
    186 }
    187 
    188 void UIHelpBrowserWidget::sltTabIndexChange(int tabIndex)
    189 {
    190     Q_UNUSED(tabIndex);
    191 
    192     /* Dont refresh the search here as it is refreshed by the filtering mechanism
    193        which is updated as tab current index changes: */
    194 
    195     /* We keep a separate QVector<LogBookmark> for each log page: */
    196     if (m_pBookmarksPanel && currentLogPage())
    197         m_pBookmarksPanel->updateBookmarkList(currentLogPage()->bookmarkVector());
    198 }
    199 
    200 void UIHelpBrowserWidget::sltFilterApplied(bool isOriginal)
    201 {
    202     if (currentLogPage())
    203         currentLogPage()->setFiltered(!isOriginal);
    204     /* Reapply the search to get highlighting etc. correctly */
    205     if (m_pSearchPanel && m_pSearchPanel->isVisible())
    206         m_pSearchPanel->refresh();
    207 }
    208 
    209 void UIHelpBrowserWidget::sltLogPageFilteredChanged(bool isFiltered)
    210 {
    211     /* Disable bookmark panel since bookmarks are stored as line numbers within
    212        the original log text and does not mean much in a reduced/filtered one. */
    213     if (m_pBookmarksPanel)
    214         m_pBookmarksPanel->disableEnableBookmarking(!isFiltered);
    215 }
    216 
    217 void UIHelpBrowserWidget::sltHandleHidePanel(UIDialogPanel *pPanel)
    218 {
    219     hidePanel(pPanel);
    220 }
    221 
    222 void UIHelpBrowserWidget::sltShowLineNumbers(bool bShowLineNumbers)
    223 {
    224     if (m_bShowLineNumbers == bShowLineNumbers)
    225         return;
    226 
    227     m_bShowLineNumbers = bShowLineNumbers;
    228     /* Set all log page instances. */
    229     for (int i = 0; i < m_logPageList.size(); ++i)
    230     {
    231         UIVMLogPage* pLogPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]);
    232         if (pLogPage)
    233             pLogPage->setShowLineNumbers(m_bShowLineNumbers);
    234     }
    235 }
    236 
    237 void UIHelpBrowserWidget::sltWrapLines(bool bWrapLines)
    238 {
    239     if (m_bWrapLines == bWrapLines)
    240         return;
    241 
    242     m_bWrapLines = bWrapLines;
    243     /* Set all log page instances. */
    244     for (int i = 0; i < m_logPageList.size(); ++i)
    245     {
    246         UIVMLogPage* pLogPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]);
    247         if (pLogPage)
    248             pLogPage->setWrapLines(m_bWrapLines);
    249     }
    250 }
    251 
    252 void UIHelpBrowserWidget::sltFontSizeChanged(int fontSize)
    253 {
    254     if (m_font.pointSize() == fontSize)
    255         return;
    256     m_font.setPointSize(fontSize);
    257     for (int i = 0; i < m_logPageList.size(); ++i)
    258     {
    259         UIVMLogPage* pLogPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]);
    260         if (pLogPage)
    261             pLogPage->setCurrentFont(m_font);
    262     }
    263 }
    264 
    265 void UIHelpBrowserWidget::sltChangeFont(QFont font)
    266 {
    267     if (m_font == font)
    268         return;
    269     m_font = font;
    270     for (int i = 0; i < m_logPageList.size(); ++i)
    271     {
    272         UIVMLogPage* pLogPage = qobject_cast<UIVMLogPage*>(m_logPageList[i]);
    273         if (pLogPage)
    274             pLogPage->setCurrentFont(m_font);
    275     }
    276 }
    277 
    278 void UIHelpBrowserWidget::sltResetOptionsToDefault()
    279 {
    280     sltShowLineNumbers(true);
    281     sltWrapLines(false);
    282     sltChangeFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
    283 
    284     if (m_pOptionsPanel)
    285     {
    286         m_pOptionsPanel->setShowLineNumbers(true);
    287         m_pOptionsPanel->setWrapLines(false);
    288         m_pOptionsPanel->setFontSizeInPoints(m_font.pointSize());
    289     }
    290 }
    291 
    292 void UIHelpBrowserWidget::prepare()
    293 {
    294     /* Load options: */
    295     loadOptions();
    296 
    297     /* Prepare stuff: */
    298     prepareActions();
    299     /* Prepare widgets: */
    300     prepareWidgets();
    301 
    302     /* Apply language settings: */
    303     retranslateUi();
    304 
    305     /* Setup escape shortcut: */
    306     manageEscapeShortCut();
    307 }
    308 
    309 void UIHelpBrowserWidget::prepareActions()
    310 {
    311 
    312 }
    313 
    314 void UIHelpBrowserWidget::prepareWidgets()
    315 {
    316     /* Create main layout: */
    317     m_pMainLayout = new QVBoxLayout(this);
    318     AssertReturnVoid(m_pMainLayout);
     167#endif
    319168}
    320169
     
    347196void UIHelpBrowserWidget::loadOptions()
    348197{
    349     m_bWrapLines = gEDataManager->logViewerWrapLines();
    350     m_bShowLineNumbers = gEDataManager->logViewerShowLineNumbers();
    351     QFont loadedFont = gEDataManager->logViewerFont();
    352     if (loadedFont != QFont())
    353         m_font = loadedFont;
    354 }
    355 
    356 void UIHelpBrowserWidget::restorePanelVisibility()
    357 {
    358     /** Reset the action states first: */
    359     foreach(QAction* pAction, m_panelActionMap.values())
    360     {
    361         pAction->blockSignals(true);
    362         pAction->setChecked(false);
    363         pAction->blockSignals(false);
    364     }
    365 
    366     /* Load the visible panel list and show them: */
    367     QStringList strNameList = gEDataManager->logViewerVisiblePanels();
    368     foreach(const QString strName, strNameList)
    369     {
    370         foreach(UIDialogPanel* pPanel, m_panelActionMap.keys())
    371         {
    372             if (strName == pPanel->panelName())
    373             {
    374                 showPanel(pPanel);
    375                 break;
    376             }
    377         }
    378     }
    379198}
    380199
    381200void UIHelpBrowserWidget::saveOptions()
    382201{
    383     /* Save a list of currently visible panels: */
    384     QStringList strNameList;
    385     foreach(UIDialogPanel* pPanel, m_visiblePanelsList)
    386         strNameList.append(pPanel->panelName());
    387     gEDataManager->setLogViewerVisiblePanels(strNameList);
    388 
    389     gEDataManager->setLogViweverOptions(m_font, m_bWrapLines, m_bShowLineNumbers);
    390202}
    391203
     
    428240void UIHelpBrowserWidget::keyPressEvent(QKeyEvent *pEvent)
    429241{
    430     /* Depending on key pressed: */
    431     switch (pEvent->key())
    432     {
    433         /* Process Back key as switch to previous tab: */
    434         case Qt::Key_Back:
    435         {
    436             if (m_pTabWidget->currentIndex() > 0)
    437             {
    438                 m_pTabWidget->setCurrentIndex(m_pTabWidget->currentIndex() - 1);
    439                 return;
    440             }
    441             break;
    442         }
    443         /* Process Forward key as switch to next tab: */
    444         case Qt::Key_Forward:
    445         {
    446             if (m_pTabWidget->currentIndex() < m_pTabWidget->count())
    447             {
    448                 m_pTabWidget->setCurrentIndex(m_pTabWidget->currentIndex() + 1);
    449                 return;
    450             }
    451             break;
    452         }
    453         default:
    454             break;
    455     }
    456     QWidget::keyPressEvent(pEvent);
    457 }
    458 
    459 QPlainTextEdit* UIHelpBrowserWidget::logPage(int pIndex) const
    460 {
    461     if (!m_pTabWidget->isEnabled())
    462         return 0;
    463     QWidget* pContainer = m_pTabWidget->widget(pIndex);
    464     if (!pContainer)
    465         return 0;
    466     QPlainTextEdit *pBrowser = pContainer->findChild<QPlainTextEdit*>();
    467     return pBrowser;
    468 }
    469 
    470 void UIHelpBrowserWidget::createLogPage(const QString &strFileName, const QString &strLogContent, bool noLogsToShow /* = false */)
    471 {
    472     if (!m_pTabWidget)
    473         return;
    474 
    475     /* Create page-container: */
    476     UIVMLogPage* pLogPage = new UIVMLogPage();
    477     if (pLogPage)
    478     {
    479         connect(pLogPage, &UIVMLogPage::sigBookmarksUpdated, this, &UIHelpBrowserWidget::sltUpdateBookmarkPanel);
    480         connect(pLogPage, &UIVMLogPage::sigLogPageFilteredChanged, this, &UIHelpBrowserWidget::sltLogPageFilteredChanged);
    481         /* Initialize setting for this log page */
    482         pLogPage->setShowLineNumbers(m_bShowLineNumbers);
    483         pLogPage->setWrapLines(m_bWrapLines);
    484         pLogPage->setCurrentFont(m_font);
    485 
    486         /* Set the file name only if we really have log file to read. */
    487         if (!noLogsToShow)
    488             pLogPage->setLogFileName(strFileName);
    489 
    490         /* Add page-container to viewer-container: */
    491         int tabIndex = m_pTabWidget->insertTab(m_pTabWidget->count(), pLogPage, QFileInfo(strFileName).fileName());
    492 
    493         pLogPage->setTabIndex(tabIndex);
    494         m_logPageList.resize(m_pTabWidget->count());
    495         m_logPageList[tabIndex] = pLogPage;
    496 
    497         /* Set text edit since we want to display this text: */
    498         if (!noLogsToShow)
    499         {
    500             pLogPage->setTextEditText(strLogContent);
    501             /* Set the log string of the UIVMLogPage: */
    502             pLogPage->setLogString(strLogContent);
    503         }
    504         /* In case there are some errors append the error text as html: */
    505         else
    506         {
    507             pLogPage->setTextEditTextAsHtml(strLogContent);
    508             pLogPage->markForError();
    509         }
    510         pLogPage->setScrollBarMarkingsVector(m_pSearchPanel->matchLocationVector());
    511     }
    512 }
    513 
    514 const UIVMLogPage *UIHelpBrowserWidget::currentLogPage() const
    515 {
    516     int currentTabIndex = m_pTabWidget->currentIndex();
    517     if (currentTabIndex >= m_logPageList.size())
    518         return 0;
    519     return qobject_cast<const UIVMLogPage*>(m_logPageList.at(currentTabIndex));
    520 }
    521 
    522 UIVMLogPage *UIHelpBrowserWidget::currentLogPage()
    523 {
    524     int currentTabIndex = m_pTabWidget->currentIndex();
    525     if (currentTabIndex >= m_logPageList.size() || currentTabIndex == -1)
    526         return 0;
    527 
    528     return qobject_cast<UIVMLogPage*>(m_logPageList.at(currentTabIndex));
    529 }
    530 
    531 void UIHelpBrowserWidget::resetHighlighthing()
    532 {
    533     /* Undo the document changes to remove highlighting: */
    534     UIVMLogPage* logPage = currentLogPage();
    535     if (!logPage)
    536         return;
    537     logPage->documentUndo();
    538     logPage->clearScrollBarMarkingsVector();
    539 }
    540 
    541 void UIHelpBrowserWidget::hidePanel(UIDialogPanel* panel)
    542 {
    543     if (!panel)
    544         return;
    545     if (panel->isVisible())
    546         panel->setVisible(false);
    547     QMap<UIDialogPanel*, QAction*>::iterator iterator = m_panelActionMap.find(panel);
    548     if (iterator != m_panelActionMap.end())
    549     {
    550         if (iterator.value() && iterator.value()->isChecked())
    551             iterator.value()->setChecked(false);
    552     }
    553     m_visiblePanelsList.removeOne(panel);
    554     manageEscapeShortCut();
    555 }
    556 
    557 void UIHelpBrowserWidget::showPanel(UIDialogPanel* panel)
    558 {
    559     if (panel && panel->isHidden())
    560         panel->setVisible(true);
    561     QMap<UIDialogPanel*, QAction*>::iterator iterator = m_panelActionMap.find(panel);
    562     if (iterator != m_panelActionMap.end())
    563     {
    564         if (!iterator.value()->isChecked())
    565             iterator.value()->setChecked(true);
    566     }
    567     m_visiblePanelsList.push_back(panel);
    568     manageEscapeShortCut();
    569 }
    570 
    571 void UIHelpBrowserWidget::manageEscapeShortCut()
    572 {
    573     /* if there is no visible panels give the escape shortcut to parent dialog: */
    574     if (m_visiblePanelsList.isEmpty())
    575     {
    576         emit sigSetCloseButtonShortCut(QKeySequence(Qt::Key_Escape));
    577         return;
    578     }
    579     /* Take the escape shortcut from the dialog: */
    580     emit sigSetCloseButtonShortCut(QKeySequence());
    581     /* Just loop thru the visible panel list and set the esc key to the
    582        panel which made visible latest */
    583     for (int i = 0; i < m_visiblePanelsList.size() - 1; ++i)
    584     {
    585         m_visiblePanelsList[i]->setCloseButtonShortCut(QKeySequence());
    586     }
    587     m_visiblePanelsList.back()->setCloseButtonShortCut(QKeySequence(Qt::Key_Escape));
    588 }
     242   QWidget::keyPressEvent(pEvent);
     243}
     244
     245
     246void UIHelpBrowserWidget::sltHandleHelpEngineSetupFinished()
     247{
     248#ifdef VBOX_WS_X11
     249    AssertReturnVoid(m_pTextBrowser && m_pHelpEngine);
     250
     251    QList<QUrl> files = m_pHelpEngine->files(m_pHelpEngine->namespaceName(m_strHelpFilePath), QStringList());
     252    if (!files.empty())
     253        m_pTextBrowser->setSource(files[0]);
     254    /*  @todo: show some kind of error maybe. */
     255#endif
     256}
     257
     258#include "UIHelpBrowserWidget.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h

    r86342 r86581  
    2323
    2424/* Qt includes: */
     25
    2526#include <QKeySequence>
    2627#include <QPair>
     
    3637
    3738/* Forward declarations: */
     39class QHelpEngine;
     40class QPlainTextEdit;
     41class UIHelpBrowserViewer;
     42class QHBoxLayout;
    3843class QITabWidget;
    39 class QPlainTextEdit;
    40 class QVBoxLayout;
     44class QIToolBar;
    4145class UIActionPool;
    4246class UIDialogPanel;
    43 class QIToolBar;
    44 class UIVMLogPage;
    45 class UIVMLogViewerBookmarksPanel;
    46 class UIVMLogViewerFilterPanel;
    47 class UIVMLogViewerPanel;
    48 class UIVMLogViewerSearchPanel;
    49 class UIVMLogViewerOptionsPanel;
    5047
    5148/** QWidget extension providing GUI for VirtualBox LogViewer. It
     
    6562      * @param  enmEmbedding  Brings the type of widget embedding.
    6663      * @param  fShowToolbar  Brings whether we should create/show toolbar.*/
    67     UIHelpBrowserWidget(EmbedTo enmEmbedding,
     64    UIHelpBrowserWidget(EmbedTo enmEmbedding, const QString &strHelpFilePath,
    6865                        bool fShowToolbar = true, QWidget *pParent = 0);
    6966    /** Destructs the VM Log-Viewer. */
    7067    ~UIHelpBrowserWidget();
    71     /** Returns the width of the current log page. return 0 if there is no current log page: */
    72     int defaultLogPageWidth() const;
    7368
    7469    /** Returns the menu. */
     
    8075#endif
    8176
    82     QFont currentFont() const;
    8377
    8478protected:
     
    8983private slots:
    9084
    91     /** @name Bookmark related slots
    92      * @{ */
    93     /** Deletes the bookmark with @p index from the current logs bookmark list. */
    94         void sltDeleteBookmark(int index);
    95         /** Receives delete all signal from the bookmark panel and notifies UIVMLogPage. */
    96         void sltDeleteAllBookmarks();
    97         /** Manages bookmark panel update when bookmark vector is updated. */
    98         void sltUpdateBookmarkPanel();
    99         /** Makes the current UIVMLogPage to goto (scroll) its bookmark with index @a index. */
    100         void gotoBookmark(int bookmarkIndex);
    101     /** @} */
    102 
    103     void sltPanelActionToggled(bool fChecked);
    104     /** Handles the search result highlight changes. */
    105     void sltSearchResultHighLigting();
    106     void sltHandleSearchUpdated();
    107     /** Handles the tab change of the logviewer. */
    108     void sltTabIndexChange(int tabIndex);
    109     /* if @a isOriginal true than the result of the filtering is equal to
    110        the original log file for some reason. */
    111     void sltFilterApplied(bool isOriginal);
    112     /* Handles the UIVMLogPage signal which is emitted when isFiltered property
    113        of UIVMLogPage is changed. */
    114     void sltLogPageFilteredChanged(bool isFiltered);
    115     void sltHandleHidePanel(UIDialogPanel *pPanel);
    116 
    117     /** @name Slots to handle signals from settings panel
    118      * @{ */
    119         void sltShowLineNumbers(bool bShowLineNumbers);
    120         void sltWrapLines(bool bWrapLine);
    121         void sltFontSizeChanged(int fontSize);
    122         void sltChangeFont(QFont font);
    123         void sltResetOptionsToDefault();
    124     /** @} */
     85    void sltHandleHelpEngineSetupFinished();
    12586
    12687private:
    12788
    128     /** @name Prepare/Cleanup
    129       * @{ */
    130         /** Prepares VM Log-Viewer. */
    131         void prepare();
    132         /** Prepares actions. */
    133         void prepareActions();
    134         /** Prepares widgets. */
    135         void prepareWidgets();
    136         /** Prepares toolbar. */
    137         void prepareToolBar();
    138         /** Loads options.  */
    139         void loadOptions();
    140         /** Shows the panels that have been visible the last time logviewer is closed. */
    141         void restorePanelVisibility();
     89    void prepare();
     90    void prepareActions();
     91    void prepareWidgets();
     92    void prepareToolBar();
     93    void loadOptions();
    14294
    143         /** Saves options.  */
    144         void saveOptions();
    145         /** Cleanups VM Log-Viewer. */
    146         void cleanup();
    147     /** @} */
     95    void saveOptions();
     96    void cleanup();
    14897
    14998    /** @name Event handling stuff.
     
    158107    /** @} */
    159108
    160 
    161     /** Returns the log-page from the tab with index @a pIndex. */
    162     QPlainTextEdit* logPage(int pIndex) const;
    163     /** Returns the newly created log-page using @a strPage filename. */
    164     void createLogPage(const QString &strFileName, const QString &strLogContent, bool noLogsToShow = false);
    165 
    166     const UIVMLogPage *currentLogPage() const;
    167     UIVMLogPage *currentLogPage();
    168 
    169     /** Resets document (of the curent tab) and scrollbar highligthing */
    170     void resetHighlighthing();
    171 
    172     void hidePanel(UIDialogPanel* panel);
    173     void showPanel(UIDialogPanel* panel);
    174 
    175     /** Make sure escape key is assigned to only a single widget. This is done by checking
    176         several things in the following order:
    177         - when there are no more panels visible assign it to the parent dialog
    178         - grab it from the dialog as soon as a panel becomes visible again
    179         - assigned it to the most recently "unhidden" panel */
    180     void manageEscapeShortCut();
    181 
    182109    /** Holds the widget's embedding type. */
    183110    const EmbedTo m_enmEmbedding;
     
    191118
    192119    /** Holds container for log-pages. */
    193     QITabWidget        *m_pTabWidget;
    194     /** Stores the UIVMLogPage instances. This is modified as we add and remove new tabs
    195      *  to the m_pTabWidget. Index is the index of the tab widget. */
    196     QVector<QWidget*>  m_logPageList;
    197 
    198     /** @name Panel instances and a QMap for mapping panel instances to related actions.
    199       * @{ */
    200         UIVMLogViewerSearchPanel    *m_pSearchPanel;
    201         UIVMLogViewerFilterPanel    *m_pFilterPanel;
    202         UIVMLogViewerBookmarksPanel *m_pBookmarksPanel;
    203         UIVMLogViewerOptionsPanel   *m_pOptionsPanel;
    204         QMap<UIDialogPanel*, QAction*> m_panelActionMap;
    205         QList<UIDialogPanel*>          m_visiblePanelsList;
    206     /** @} */
    207     QVBoxLayout         *m_pMainLayout;
    208 
     120    QHBoxLayout         *m_pMainLayout;
     121    QITabWidget *m_pTabWidget;
    209122    /** @name Toolbar and menu variables.
    210123      * @{ */
     
    212125    /** @} */
    213126
    214     /** @name Toolbar and menu variables. Cache these to restore them after refresh.
    215      * @{ */
    216         /** Showing/hiding line numbers and line wraping options are set per
    217             UIHelpBrowserWidget and applies to all log pages (all tabs) */
    218         bool  m_bShowLineNumbers;
    219         bool  m_bWrapLines;
    220         QFont m_font;
    221     /** @} */
     127    QString       m_strHelpFilePath;
     128#ifdef VBOX_WS_X11
     129    QHelpEngine  *m_pHelpEngine;
     130#endif
     131    UIHelpBrowserViewer *m_pTextBrowser;
    222132};
    223133
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette