VirtualBox

Ignore:
Timestamp:
Jul 12, 2014 7:18:36 AM (10 years ago)
Author:
vboxsync
Message:

Debugger/VBoxDbgConsole: Add context-menu options to change color and font scheme.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/VBoxDbgConsole.cpp

    r49276 r52002  
    3030#include <QAction>
    3131#include <QContextMenuEvent>
     32#include <QMenu>
    3233
    3334#include <VBox/dbg.h>
     
    6869    setAcceptRichText(false);
    6970
     71    /*
     72     * Font.
     73     * Create actions for font menu items.
     74     */
     75    m_pCourierFontAction = new QAction(tr("Courier"), this);
     76    m_pCourierFontAction->setCheckable(true);
     77    m_pCourierFontAction->setShortcut(Qt::ControlModifier + Qt::Key_D);
     78    connect(m_pCourierFontAction, SIGNAL(triggered()), this, SLOT(setFontCourier()));
     79
     80    m_pMonospaceFontAction = new QAction(tr("Monospace"), this);
     81    m_pMonospaceFontAction->setCheckable(true);
     82    m_pMonospaceFontAction->setShortcut(Qt::ControlModifier + Qt::Key_M);
     83    connect(m_pMonospaceFontAction, SIGNAL(triggered()), this, SLOT(setFontMonospace()));
     84
     85    /* Create action group for grouping of exclusive font menu items. */
     86    QActionGroup *pActionFontGroup = new QActionGroup(this);
     87    pActionFontGroup->addAction(m_pCourierFontAction);
     88    pActionFontGroup->addAction(m_pMonospaceFontAction);
     89    pActionFontGroup->setExclusive(true);
     90
     91    /*
     92     * Color scheme.
     93     * Create actions for color-scheme menu items.
     94     */
     95    m_pGreenOnBlackAction = new QAction(tr("Green On Black"), this);
     96    m_pGreenOnBlackAction->setCheckable(true);
     97    m_pGreenOnBlackAction->setShortcut(Qt::ControlModifier + Qt::Key_1);
     98    connect(m_pGreenOnBlackAction, SIGNAL(triggered()), this, SLOT(setColorGreenOnBlack()));
     99
     100    m_pBlackOnWhiteAction = new QAction(tr("Black On White"), this);
     101    m_pBlackOnWhiteAction->setCheckable(true);
     102    m_pBlackOnWhiteAction->setShortcut(Qt::ControlModifier + Qt::Key_2);
     103    connect(m_pBlackOnWhiteAction, SIGNAL(triggered()), this, SLOT(setColorBlackOnWhite()));
     104
     105    /* Create action group for grouping of exclusive color-scheme menu items. */
     106    QActionGroup *pActionColorGroup = new QActionGroup(this);
     107    pActionColorGroup->addAction(m_pGreenOnBlackAction);
     108    pActionColorGroup->addAction(m_pBlackOnWhiteAction);
     109    pActionColorGroup->setExclusive(true);
     110
     111    /*
     112     * Set the defaults (which syncs with the menu item checked state).
     113     */
     114    setFontCourier();
     115    setColorGreenOnBlack();
     116
     117    NOREF(pszName);
     118}
     119
     120
     121VBoxDbgConsoleOutput::~VBoxDbgConsoleOutput()
     122{
     123    Assert(m_hGUIThread == RTThreadNativeSelf());
     124}
     125
     126
     127void
     128VBoxDbgConsoleOutput::contextMenuEvent(QContextMenuEvent *pEvent)
     129{
     130    /*
     131     * Create the context menu and add the menu items.
     132     */
     133    QMenu *pMenu = createStandardContextMenu();
     134    QMenu *pColorMenu = pMenu->addMenu(tr("Co&lor Scheme"));
     135    pColorMenu->addAction(m_pGreenOnBlackAction);
     136    pColorMenu->addAction(m_pBlackOnWhiteAction);
     137
     138    QMenu *pFontMenu = pMenu->addMenu(tr("&Font Family"));
     139    pFontMenu->addAction(m_pCourierFontAction);
     140    pFontMenu->addAction(m_pMonospaceFontAction);
     141
     142    pMenu->exec(pEvent->globalPos());
     143    delete pMenu;
     144}
     145
     146
     147void
     148VBoxDbgConsoleOutput::setColorGreenOnBlack()
     149{
     150    setStyleSheet("QTextEdit { background-color: black; color: rgb(0, 224, 0) }");
     151    m_enmColorScheme = kGreenOnBlack;
     152
     153    /* This is used both as a trigger as well as called independently from code.
     154       When used as a trigger, the checked is done automatically by Qt. */
     155    if (!m_pGreenOnBlackAction->isChecked())
     156        m_pGreenOnBlackAction->setChecked(true);
     157}
     158
     159
     160void
     161VBoxDbgConsoleOutput::setColorBlackOnWhite()
     162{
     163    setStyleSheet("QTextEdit { background-color: white; color: black }");
     164    m_enmColorScheme = kBlackOnWhite;
     165
     166    if (!m_pBlackOnWhiteAction->isChecked())
     167        m_pBlackOnWhiteAction->setChecked(true);
     168}
     169
     170
     171void
     172VBoxDbgConsoleOutput::setFontCourier()
     173{
    70174#ifdef Q_WS_MAC
    71175    QFont Font("Monaco", 10, QFont::Normal, FALSE);
     
    78182    setFont(Font);
    79183
    80     /* green on black */
    81     QPalette Pal(palette());
    82     Pal.setColor(QPalette::All, QPalette::Base, QColor(Qt::black));
    83     setPalette(Pal);
    84     setTextColor(QColor(qRgb(0, 0xe0, 0)));
    85 
    86 #ifdef DEBUG_ramshankar
    87     /* Solaris host (esp. S10) has illegible Courier font (bad aliasing). */
     184    if (!m_pCourierFontAction->isChecked())
     185        m_pCourierFontAction->setChecked(true);
     186}
     187
     188
     189void
     190VBoxDbgConsoleOutput::setFontMonospace()
     191{
     192    QFont Font = font();
     193    Font.setStyleHint(QFont::TypeWriter);
     194    Font.setStyleStrategy(QFont::PreferAntialias);
    88195    Font.setFamily("Monospace [Monotype]");
    89196    setFont(Font);
    90197
    91     /* White on black while I'm at it. */
    92     Pal.setColor(QPalette::All, QPalette::Base, QColor(Qt::white));
    93     setPalette(Pal);
    94     setTextColor(QColor(qRgb(0, 0, 0)));
    95 #endif
    96 
    97     NOREF(pszName);
    98 }
    99 
    100 
    101 VBoxDbgConsoleOutput::~VBoxDbgConsoleOutput()
    102 {
    103     Assert(m_hGUIThread == RTThreadNativeSelf());
     198    if (!m_pMonospaceFontAction->isChecked())
     199        m_pMonospaceFontAction->setChecked(true);
    104200}
    105201
     
    366462    addAction(m_pFocusToOutput);
    367463    connect(m_pFocusToOutput, SIGNAL(triggered(bool)), this, SLOT(actFocusToOutput()));
     464
     465    addAction(m_pOutput->m_pBlackOnWhiteAction);
     466    addAction(m_pOutput->m_pGreenOnBlackAction);
     467    addAction(m_pOutput->m_pCourierFontAction);
     468    addAction(m_pOutput->m_pMonospaceFontAction);
    368469}
    369470
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