VirtualBox

Ignore:
Timestamp:
Dec 12, 2017 9:26:08 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: ​​bugref:9072 Adding toolbar and menu to logviewer dialog

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIManagerDialog.cpp

    r70029 r70074  
    191191void QIManagerDialog::prepareToolBar()
    192192{
     193    if(!m_pWidgetToolbar)
     194        return;
    193195    /* Enable unified toolbar on macOS: */
    194196    addToolBar(m_pWidgetToolbar);
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.cpp

    r70029 r70074  
    5858{
    5959    button(ButtonType_Close)->setText(UIVMLogViewerWidget::tr("Close"));
     60    button(ButtonType_Close)->setShortcut(Qt::Key_Escape);
     61    /* Setup a dialog caption: */
     62    if (!m_comMachine.isNull())
     63        setWindowTitle(tr("%1 - Log Viewer").arg(m_comMachine.GetName()));
     64    else
     65        setWindowTitle(UIVMLogViewerWidget::tr("Log Viewer"));
    6066}
    6167
     
    6369{
    6470    /* Create widget: */
    65     UIVMLogViewerWidget *pWidget = new UIVMLogViewerWidget(this, m_comMachine);
     71    UIVMLogViewerWidget *pWidget = new UIVMLogViewerWidget(EmbedTo_Dialog, this, m_comMachine);
    6672    AssertPtrReturnVoid(pWidget);
    6773    {
    6874        /* Configure widget: */
    6975        setWidget(pWidget);
    70         //setWidgetMenu(pWidget->menu());
     76        setWidgetMenu(pWidget->menu());
    7177#ifdef VBOX_WS_MAC
    72         //setWidgetToolbar(pWidget->toolbar());
     78        setWidgetToolbar(pWidget->toolbar());
    7379#endif
    7480        /* Add into layout: */
     
    8086{
    8187    /* Apply window icons: */
    82     setWindowIcon(UIIconPool::iconSetFull(":/diskimage_32px.png", ":/diskimage_16px.png"));
     88    setWindowIcon(UIIconPool::iconSetFull(":/vm_show_logs_32px.png", ":/vm_show_logs_16px.png"));
    8389}
     90
     91void UIVMLogViewerDialog::finalize()
     92{
     93    retranslateUi();
     94}
     95
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.h

    r70029 r70074  
    6363    virtual void configure() /* override */;
    6464    virtual void configureCentralWidget() /* override */;
     65    virtual void finalize() /* override */;
    6566
    6667private:
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70029 r70074  
    2323# include <QDateTime>
    2424# include <QDir>
    25 # include <QDialogButtonBox>
    2625# include <QVBoxLayout>
    2726# if defined(RT_OS_SOLARIS)
    2827#  include <QFontDatabase>
    2928# endif
    30 # include <QPushButton>
    3129# include <QTextEdit>
    3230
     
    4038# include "UIVMLogViewerFilterPanel.h"
    4139# include "UIVMLogViewerSearchPanel.h"
     40# include "UIToolBar.h"
    4241
    4342/* COM includes: */
     
    4847#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4948
    50 UIVMLogViewerWidget::UIVMLogViewerWidget(QWidget *pParent, const CMachine &machine)
     49UIVMLogViewerWidget::UIVMLogViewerWidget(EmbedTo enmEmbedding, QWidget *pParent, const CMachine &machine)
    5150    : QIWithRetranslateUI<QWidget>(pParent)
    5251    , m_fIsPolished(false)
    5352    , m_comMachine(machine)
    54     , m_pButtonBox(0)
    5553    , m_pMainLayout(0)
    56     , m_pButtonFind(0)
    57     , m_pButtonRefresh(0)
    58     , m_pButtonSave(0)
    59     , m_pButtonFilter(0)
    60 
     54    , m_enmEmbedding(enmEmbedding)
     55    , m_pToolBar(0)
     56    , m_pActionFind(0)
     57    , m_pActionFilter(0)
     58    , m_pActionRefresh(0)
     59    , m_pActionSave(0)
     60    , m_pMenu(0)
    6161{
    6262    /* Prepare VM Log-Viewer: */
     
    9090}
    9191
    92 void UIVMLogViewerWidget::search()
     92void UIVMLogViewerWidget::sltFind()
    9393{
    9494    /* Show/hide search-panel: */
     
    9696}
    9797
    98 void UIVMLogViewerWidget::refresh()
     98void UIVMLogViewerWidget::sltRefresh()
    9999{
    100100    /* Disconnect this connection to avoid initial signals during page creation/deletion: */
     
    176176    connect(m_pViewerContainer, SIGNAL(currentChanged(int)), m_pFilterPanel, SLOT(applyFilter(int)));
    177177
    178     /* Enable/Disable save button & tab widget according log presence: */
    179     m_pButtonFind->setEnabled(isAnyLogPresent);
    180     m_pButtonSave->setEnabled(isAnyLogPresent);
    181     m_pButtonFilter->setEnabled(isAnyLogPresent);
     178    /* Enable/Disable toolbar actions (except Refresh) & tab widget according log presence: */
     179    m_pActionFind->setEnabled(isAnyLogPresent);
     180    m_pActionFilter->setEnabled(isAnyLogPresent);
     181    m_pActionSave->setEnabled(isAnyLogPresent);
    182182    m_pViewerContainer->setEnabled(isAnyLogPresent);
    183183}
    184184
    185 void UIVMLogViewerWidget::save()
     185void UIVMLogViewerWidget::sltSave()
    186186{
    187187    /* Prepare "save as" dialog: */
     
    211211}
    212212
    213 void UIVMLogViewerWidget::filter()
     213void UIVMLogViewerWidget::sltFilter()
    214214{
    215215    /* Show/hide filter-panel: */
     
    219219void UIVMLogViewerWidget::prepare()
    220220{
    221     m_pButtonBox = new QDialogButtonBox(this);
    222221    m_pMainLayout = new QVBoxLayout(this);
    223222
    224     m_pMainLayout->addWidget(m_pButtonBox);
    225 
    226     /* Apply window icons: */
    227     setWindowIcon(UIIconPool::iconSetFull(":/vm_show_logs_32px.png", ":/vm_show_logs_16px.png"));
     223    prepareActions();
     224
     225    prepareToolBar();
     226    prepareMenu();
    228227
    229228    /* Prepare widgets: */
    230229    prepareWidgets();
    231230
    232     /* Prepare connections: */
    233     prepareConnections();
    234 
    235231    /* Reading log files: */
    236     refresh();
     232    sltRefresh();
    237233
    238234    /* Loading language constants: */
     
    247243    {
    248244        /* Add VM Log-Viewer container to main-layout: */
    249         m_pMainLayout->insertWidget(0, m_pViewerContainer);
     245        m_pMainLayout->insertWidget(1, m_pViewerContainer);
    250246    }
    251247
     
    258254        m_pSearchPanel->hide();
    259255        /* Add VM Log-Viewer search-panel to main-layout: */
    260         m_pMainLayout->insertWidget(1, m_pSearchPanel);
     256        m_pMainLayout->insertWidget(2, m_pSearchPanel);
    261257    }
    262258
     
    269265        m_pFilterPanel->hide();
    270266        /* Add VM Log-Viewer filter-panel to main-layout: */
    271         m_pMainLayout->insertWidget(2, m_pFilterPanel);
    272     }
    273 
    274     /* Create find-button: */
    275     m_pButtonFind = m_pButtonBox->addButton(QString::null, QDialogButtonBox::ActionRole);
    276     AssertPtrReturnVoid(m_pButtonFind);
    277     /* Create filter-button: */
    278     m_pButtonFilter = m_pButtonBox->addButton(QString::null, QDialogButtonBox::ActionRole);
    279     AssertPtrReturnVoid(m_pButtonFilter);
    280 
    281     /* Create save-button: */
    282     m_pButtonSave = m_pButtonBox->addButton(QDialogButtonBox::Save);
    283     AssertPtrReturnVoid(m_pButtonSave);
    284     /* Create refresh-button: */
    285     m_pButtonRefresh = m_pButtonBox->addButton(QString::null, QDialogButtonBox::ActionRole);
    286     AssertPtrReturnVoid(m_pButtonRefresh);
    287 }
    288 
    289 void UIVMLogViewerWidget::prepareConnections()
    290 {
    291     /* Prepare connections: */
    292     connect(m_pButtonBox, SIGNAL(helpRequested()), &msgCenter(), SLOT(sltShowHelpHelpDialog()));
    293     connect(m_pButtonFind, SIGNAL(clicked()), this, SLOT(search()));
    294     connect(m_pButtonRefresh, SIGNAL(clicked()), this, SLOT(refresh()));
    295     connect(m_pButtonSave, SIGNAL(clicked()), this, SLOT(save()));
    296     connect(m_pButtonFilter, SIGNAL(clicked()), this, SLOT(filter()));
     267        m_pMainLayout->insertWidget(3, m_pFilterPanel);
     268    }
     269}
     270
     271void UIVMLogViewerWidget::prepareActions()
     272{
     273    /* Create and configure 'Find' action: */
     274    m_pActionFind = new QAction(this);
     275    AssertPtrReturnVoid(m_pActionFind);
     276    {
     277        m_pActionFind->setShortcut(QKeySequence("Ctrl+F"));
     278        connect(m_pActionFind, &QAction::triggered, this, &UIVMLogViewerWidget::sltFind);
     279    }
     280
     281    /* Create and configure 'Filter' action: */
     282    m_pActionFilter = new QAction(this);
     283    AssertPtrReturnVoid(m_pActionFilter);
     284    {
     285        m_pActionFilter->setShortcut(QKeySequence("Ctrl+T"));
     286        connect(m_pActionFilter, &QAction::triggered, this, &UIVMLogViewerWidget::sltFilter);
     287    }
     288
     289    /* Create and configure 'Refresh' action: */
     290    m_pActionRefresh = new QAction(this);
     291    AssertPtrReturnVoid(m_pActionRefresh);
     292    {
     293        m_pActionRefresh->setShortcut(QKeySequence("F5"));
     294        connect(m_pActionRefresh, &QAction::triggered, this, &UIVMLogViewerWidget::sltRefresh);
     295    }
     296
     297    /* Create and configure 'Save' action: */
     298    m_pActionSave = new QAction(this);
     299    AssertPtrReturnVoid(m_pActionSave);
     300    {
     301        m_pActionSave->setShortcut(QKeySequence("Ctrl+S"));
     302        connect(m_pActionSave, &QAction::triggered, this, &UIVMLogViewerWidget::sltSave);
     303    }
     304
     305    /* Update action icons: */
     306    prepareActionIcons();
     307}
     308
     309void UIVMLogViewerWidget::prepareActionIcons()
     310{
     311    QString strPrefix = "log_viewer";
     312
     313    if (m_pActionFind)
     314        m_pActionFind->setIcon(UIIconPool::iconSet(QString(":/%1_find_24px.png").arg(strPrefix),
     315                                                       QString(":/%1_find_disabled_24px.png").arg(strPrefix)));
     316
     317    if (m_pActionFilter)
     318        m_pActionFilter->setIcon(UIIconPool::iconSet(QString(":/%1_filter_24px.png").arg(strPrefix),
     319                                                         QString(":/%1_filter_disabled_24px.png").arg(strPrefix)));
     320
     321
     322    if (m_pActionRefresh)
     323        m_pActionRefresh->setIcon(UIIconPool::iconSet(QString(":/%1_refresh_24px.png").arg(strPrefix),
     324                                                          QString(":/%1_refresh_disabled_24px.png").arg(strPrefix)));
     325
     326
     327    if (m_pActionSave)
     328        m_pActionSave->setIcon(UIIconPool::iconSet(QString(":/%1_save_24px.png").arg(strPrefix),
     329                                                       QString(":/%1_save_disabled_24px.png").arg(strPrefix)));
     330
     331
     332}
     333
     334void UIVMLogViewerWidget::prepareToolBar()
     335{
     336    /* Create toolbar: */
     337    m_pToolBar = new UIToolBar(parentWidget());
     338    AssertPtrReturnVoid(m_pToolBar);
     339    {
     340        /* Configure toolbar: */
     341        const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * 1.375);
     342        m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric));
     343        m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
     344        /* Add toolbar actions: */
     345        if (m_pActionFind)
     346            m_pToolBar->addAction(m_pActionFind);
     347
     348        if (m_pActionFilter)
     349            m_pToolBar->addAction(m_pActionFilter);
     350
     351        if (m_pActionRefresh)
     352            m_pToolBar->addAction(m_pActionRefresh);
     353
     354        if (m_pActionSave)
     355            m_pToolBar->addAction(m_pActionSave);
     356
     357#ifdef VBOX_WS_MAC
     358        /* Check whether we are embedded into a stack: */
     359        if (m_enmEmbedding == EmbedTo_Stack)
     360        {
     361            /* Add into layout: */
     362            layout()->addWidget(m_pToolBar);
     363        }
     364#else
     365        /* Add into layout: */
     366        m_pMainLayout->insertWidget(0, m_pToolBar);
     367#endif
     368    }
     369}
     370
     371void UIVMLogViewerWidget::prepareMenu()
     372{
     373    /* Create 'LogViewer' menu: */
     374    m_pMenu = new QMenu(this);
     375    AssertPtrReturnVoid(m_pMenu);
     376    {
     377        if (m_pActionFind)
     378            m_pMenu->addAction(m_pActionFind);
     379        if (m_pActionFilter)
     380            m_pMenu->addAction(m_pActionFilter);
     381        if (m_pActionRefresh)
     382            m_pMenu->addAction(m_pActionRefresh);
     383        if (m_pActionSave)
     384            m_pMenu->addAction(m_pActionSave);
     385    }
    297386}
    298387
     
    303392void UIVMLogViewerWidget::retranslateUi()
    304393{
    305     /* Setup a dialog caption: */
    306     if (!m_comMachine.isNull())
    307         setWindowTitle(tr("%1 - VirtualBox Log Viewer").arg(m_comMachine.GetName()));
    308 
    309     /* Translate other tags: */
    310     m_pButtonFind->setText(tr("&Find"));
    311     m_pButtonRefresh->setText(tr("&Refresh"));
    312     m_pButtonSave->setText(tr("&Save"));
    313     m_pButtonFilter->setText(tr("Fil&ter"));
     394    if(m_pMenu)
     395    {
     396        m_pMenu->setTitle(tr("&Log Viewer"));
     397    }
     398
     399    if (m_pActionFind)
     400    {
     401        m_pActionFind->setText(tr("&Find..."));
     402        m_pActionFind->setToolTip(tr("Find a string within the log"));
     403        m_pActionFind->setStatusTip(tr("Find a string within the log"));
     404    }
     405
     406    if (m_pActionFilter)
     407    {
     408        m_pActionFilter->setText(tr("&Filter..."));
     409        m_pActionFilter->setToolTip(tr("Filter the log wrt. the given string"));
     410        m_pActionFilter->setStatusTip(tr("Filter the log wrt. the given string"));
     411    }
     412
     413    if (m_pActionRefresh)
     414    {
     415        m_pActionRefresh->setText(tr("&Refresh..."));
     416        m_pActionRefresh->setToolTip(tr("Reload the log"));
     417        m_pActionRefresh->setStatusTip(tr("Reload the log"));
     418    }
     419
     420    if (m_pActionSave)
     421    {
     422        m_pActionSave->setText(tr("&Save..."));
     423        m_pActionSave->setToolTip(tr("Save the log"));
     424        m_pActionSave->setStatusTip(tr("Save the log"));
     425    }
     426
     427    /* Translate toolbar: */
     428#ifdef VBOX_WS_MAC
     429    // WORKAROUND:
     430    // There is a bug in Qt Cocoa which result in showing a "more arrow" when
     431    // the necessary size of the toolbar is increased. Also for some languages
     432    // the with doesn't match if the text increase. So manually adjust the size
     433    // after changing the text. */
     434    if (m_pToolBar)
     435        m_pToolBar->updateLayout();
     436#endif
    314437}
    315438
     
    424547    return m_logMap[currentLogPage()];
    425548}
     549
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r70029 r70074  
    2525
    2626/* GUI includes: */
     27#include "QIManagerDialog.h"
    2728#include "QIWithRetranslateUI.h"
    2829
     
    3233
    3334/* Forward declarations: */
    34 class QDialogButtonBox;
    3535class QITabWidget;
    36 class QPushButton;
    3736class QTextEdit;
    3837class QVBoxLayout;
     38class UIToolBar;
    3939class UIVMLogViewerFilterPanel;
    4040class UIVMLogViewerSearchPanel;
     
    5454    /** Constructs the VM Log-Viewer by passing @a pParent to QWidget base-class constructor.
    5555      * @param  machine  Specifies the machine for which VM Log-Viewer is requested. */
    56     UIVMLogViewerWidget(QWidget *pParent, const CMachine &machine);
     56    UIVMLogViewerWidget(EmbedTo enmEmbedding, QWidget *pParent, const CMachine &machine);
    5757    /** Destructs the VM Log-Viewer. */
    5858    ~UIVMLogViewerWidget();
     
    6060    int currentLogPagewidth() const;
    6161
     62    /** Returns the menu. */
     63    QMenu *menu() const { return m_pMenu; }
     64
     65#ifdef VBOX_WS_MAC
     66    /** Returns the toolbar. */
     67    UIToolBar *toolbar() const { return m_pToolBar; }
     68#endif
     69   
    6270protected:
    6371
     
    6977
    7078    /** Handles search action triggering. */
    71     void search();
     79    void sltFind();
    7280    /** Handles refresh action triggering. */
    73     void refresh();
     81    void sltRefresh();
    7482    /** Handles save action triggering. */
    75     void save();
     83    void sltSave();
    7684    /** Handles filter action triggering. */
    77     void filter();
     85    void sltFilter();
    7886
    7987private:
     
    8593        /** Prepares widgets. */
    8694        void prepareWidgets();
    87         /** Prepares connections. */
    88         void prepareConnections();
     95        void prepareActions();
     96        void prepareActionIcons();
     97        void prepareToolBar();
     98        void prepareMenu();
    8999
    90100        /** Cleanups VM Log-Viewer. */
     
    110120    const QString& currentLog();
    111121
    112 
    113122    /** Holds whether the dialog is polished. */
    114123    bool m_fIsPolished;
     
    132141    VMLogMap m_logMap;
    133142
    134     QDialogButtonBox *m_pButtonBox;
    135143    QVBoxLayout      *m_pMainLayout;
    136144
    137     /** Holds the find button instance. */
    138     QPushButton *m_pButtonFind;
    139     /** Holds the refresh button instance. */
    140     QPushButton *m_pButtonRefresh;
    141     /** Holds the save button instance. */
    142     QPushButton *m_pButtonSave;
    143     /** Holds the filter button instance. */
    144     QPushButton *m_pButtonFilter;
     145    /** Holds the widget embedding type. */
     146    const EmbedTo m_enmEmbedding;
     147
     148    /** @name Toolbar and menu variables.
     149      * @{ */
     150        /** Holds the toolbar widget instance. */
     151        UIToolBar *m_pToolBar;
     152        /** Holds the Find action instance. */
     153        QAction   *m_pActionFind;
     154        /** Holds the Filter action instance. */
     155        QAction   *m_pActionFilter;
     156        /** Holds the Refresh action instance. */
     157        QAction   *m_pActionRefresh;
     158        /** Holds the Save action instance. */
     159        QAction   *m_pActionSave;
     160        /** Holds the menu object instance. */
     161        QMenu     *m_pMenu;
     162    /** @} */
    145163
    146164    friend class UIVMLogViewerSearchPanel;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r70031 r70074  
    10241024            continue;
    10251025
    1026         /* Show VM Log Viewer: */
     1026        QIManagerDialog *pLogViewerDialog = 0;
     1027        /* Create and Show VM Log Viewer: */
    10271028        if (!m_logViewers[pItem->machine().GetHardwareUUID()])
    10281029        {
    1029             QIManagerDialog *pLogViewerDialog;
    10301030            UIVMLogViewerDialogFactory dialogFactory(pItem->machine());
    10311031            dialogFactory.prepare(pLogViewerDialog, this);
     
    10331033            {
    10341034                m_logViewers[pItem->machine().GetHardwareUUID()] = pLogViewerDialog;
    1035 
    1036                 /* Show instance: */
    1037                 pLogViewerDialog->show();
    1038                 pLogViewerDialog->setWindowState(pLogViewerDialog->windowState() & ~Qt::WindowMinimized);
    1039                 pLogViewerDialog->activateWindow();
    10401035                connect(pLogViewerDialog, &QIManagerDialog::sigClose,
    10411036                        this, &UISelectorWindow::sltCloseLogViewerWindow);
    10421037            }
     1038        }
     1039        else
     1040        {
     1041            pLogViewerDialog = m_logViewers[pItem->machine().GetHardwareUUID()];
     1042        }
     1043        if (pLogViewerDialog)
     1044        {
     1045            /* Show instance: */
     1046            pLogViewerDialog->show();
     1047            pLogViewerDialog->setWindowState(pLogViewerDialog->windowState() & ~Qt::WindowMinimized);
     1048            pLogViewerDialog->activateWindow();
    10431049        }
    10441050    }
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