VirtualBox

Changeset 7590 in vbox


Ignore:
Timestamp:
Mar 27, 2008 1:21:57 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
29085
Message:

FE/Qt4: Ported console window to qt4.

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleView.h

    r7512 r7590  
    2626
    2727/* Qt includes */
    28 #include <q3scrollview.h>
     28#include <QAbstractScrollArea>
     29#include <QScrollBar>
    2930
    3031#if defined (Q_WS_PM)
     
    4647class QMenuData;
    4748
    48 class VBoxConsoleView : public Q3ScrollView
     49class VBoxConsoleView : public QAbstractScrollArea
    4950{
    5051    Q_OBJECT
     
    6465                     const CConsole &console,
    6566                     VBoxDefs::RenderMode rm,
    66                      QWidget *parent = 0, const char *name = 0, Qt::WFlags f = 0);
     67                     QWidget *parent = 0);
    6768    ~VBoxConsoleView();
    6869
     
    9596
    9697    QRect getDesktopGeometry();
     98
     99    /* todo: This are some support functions for the qt4 port. Maybe we get rid
     100     * of them some day. */
     101    int contentsX() const { return horizontalScrollBar()->value(); }
     102    int contentsY() const { return verticalScrollBar()->value(); }
     103    int contentsWidth() const;
     104    int contentsHeight() const;
     105    int visibleWidth() const { return horizontalScrollBar()->pageStep(); }
     106    int visibleHeight() const { return verticalScrollBar()->pageStep(); }
     107    void scrollBy (int dx, int dy)
     108    {
     109        horizontalScrollBar()->setValue (horizontalScrollBar()->value() + dx);
     110        verticalScrollBar()->setValue (verticalScrollBar()->value() + dy);
     111    }
     112    QPoint viewportToContents ( const QPoint & vp ) const
     113    {
     114        return QPoint (vp.x() + contentsX(),
     115                       vp.y() + contentsY());
     116    }
     117    void updateSliders();
    97118
    98119signals:
     
    141162    bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
    142163                     Qt::ButtonState aButton,
    143                      Qt::ButtonState aState, Qt::ButtonState aStateAfter,
     164                     Qt::MouseButtons aButtons, Qt::KeyboardModifiers aModifiers,
    144165                     int aWheelDelta, Qt::Orientation aWheelDir);
    145166
     
    162183    void doRefresh();
    163184
    164     void viewportPaintEvent( QPaintEvent * );
     185    void resizeEvent (QResizeEvent *);
     186    void paintEvent (QPaintEvent *);
    165187#ifdef VBOX_GUI_USE_REFRESH_TIMER
    166188    void timerEvent( QTimerEvent * );
     
    170192    void captureMouse (bool aCapture, bool aEmitSignal = true);
    171193
    172     bool processHotKey (const QKeySequence &key, QMenuData *data);
     194    bool processHotKey (const QKeySequence &key, const QList<QAction*>& data);
    173195    void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
    174196
     
    235257    long muCapsLockAdaptionCnt;
    236258
    237     QTimer *resize_hint_timer;
    238259    QTimer *mToggleFSModeTimer;
    239260
  • TabularUnified trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp

    r7512 r7590  
    259259{
    260260public:
    261     ActivateMenuEvent (QMenuData *menuData, uint index) :
     261    ActivateMenuEvent (QAction *aData) :
    262262        QEvent ((QEvent::Type) VBoxDefs::ActivateMenuEventType),
    263         md (menuData), i (index) {}
    264     QMenuData *menuData() const { return md; }
    265     uint index() const { return i; }
     263        mAction (aData) {}
     264    QAction *action() const { return mAction; }
    266265private:
    267     QMenuData *md;
    268     uint i;
     266    QAction *mAction;
    269267};
    270268
     
    574572#endif
    575573
     574class VBoxViewport: public QWidget
     575{
     576public:
     577    VBoxViewport (QWidget *aParent)
     578        : QWidget (aParent)
     579    {
     580        /* No need for background drawing */
     581        setAttribute (Qt::WA_OpaquePaintEvent);
     582    }
     583    virtual QPaintEngine * paintEngine() const
     584    {
     585        if (testAttribute (Qt::WA_PaintOnScreen))
     586            return NULL;
     587        else
     588            return QWidget::paintEngine();
     589    }
     590};
     591
    576592//
    577593// VBoxConsoleView class
     
    587603                                  const CConsole &console,
    588604                                  VBoxDefs::RenderMode rm,
    589                                   QWidget *parent, const char *name, Qt::WFlags f)
    590     : Q3ScrollView (parent, name, f | Qt::WStaticContents | Qt::WNoAutoErase)
     605                                  QWidget *parent)
     606    : QAbstractScrollArea (parent)
    591607    , mMainWnd (mainWnd)
    592608    , mConsole (console)
     
    630646#endif
    631647
     648    VBoxViewport *pViewport = new VBoxViewport (this);
     649    setViewport (pViewport);
     650
    632651    /* enable MouseMove events */
    633652    viewport()->setMouseTracking (true);
     
    652671    ::memset (mPressedKeys, 0, SIZEOF_ARRAY (mPressedKeys));
    653672
    654     resize_hint_timer = new QTimer (this);
    655     connect (resize_hint_timer, SIGNAL (timeout()),
    656              this, SLOT (doResizeHint()));
    657 
    658673    mToggleFSModeTimer = new QTimer (this);
    659674    mToggleFSModeTimer->setSingleShot (true);
     
    688703#if defined (VBOX_GUI_USE_SDL)
    689704        case VBoxDefs::SDLMode:
     705            /* Indicate that we are doing all
     706             * drawing stuff ourself */
     707            pViewport->setAttribute (Qt::WA_PaintOnScreen);
    690708# ifdef Q_WS_X11
    691709            /* This is somehow necessary to prevent strange X11 warnings on
     
    10581076
    10591077                if (mToggleFSModeTimer->isActive())
    1060                     mToggleFSModeTimer->stop();
     1078                    mToggleFSModeTimer->stop(); 
    10611079
    10621080                /* do frame buffer dependent resize */
     
    10801098
    10811099                /* resize the guest canvas */
    1082                 resizeContents (re->width(), re->height());
     1100                resize (re->width(), re->height());
     1101                updateSliders();
    10831102                /* let our toplevel widget calculate its sizeHint properly */
    10841103                QApplication::sendPostedEvents (0, QEvent::LayoutRequest);
     
    12211240            {
    12221241                ActivateMenuEvent *ame = (ActivateMenuEvent *) e;
    1223 #warning port me
    1224 //                ame->menuData()->activateItemAt (ame->index());
     1242                ame->action()->trigger();
    12251243
    12261244                /*
     
    14141432                        /* process hot keys not processed in keyEvent()
    14151433                         * (as in case of non-alphanumeric keys) */
    1416 #warning port me
    1417 //                        processHotKey (QKeySequence (ke->key()),
    1418 //                                       mMainWnd->menuBar());
     1434                        processHotKey (QKeySequence (ke->key()),
     1435                                       mMainWnd->menuBar()->actions());
    14191436                    }
    14201437                }
     
    14611478    }
    14621479
    1463     return Q3ScrollView::event (e);
     1480    return QAbstractScrollArea::event (e);
    14641481}
    14651482
     
    14771494                QMouseEvent *me = (QMouseEvent *) e;
    14781495                if (mouseEvent (me->type(), me->pos(), me->globalPos(),
    1479                                 me->button(), me->state(), me->stateAfter(),
     1496                                me->button(), me->buttons(), me->modifiers(),
    14801497                                0, Qt::Horizontal))
    14811498                    return true; /* stop further event handling */
     
    14861503                QWheelEvent *we = (QWheelEvent *) e;
    14871504                if (mouseEvent (we->type(), we->pos(), we->globalPos(),
    1488                                 Qt::NoButton, we->state(), we->state(),
     1505                                Qt::NoButton, we->buttons(), we->modifiers(),
    14891506                                we->delta(), we->orientation()))
    14901507                    return true; /* stop further event handling */
     
    15551572                if (!mIgnoreMainwndResize &&
    15561573                    mIsAdditionsActive && mAutoresizeGuest)
    1557                     resize_hint_timer->start (300, TRUE);
     1574                    QTimer::singleShot (300, this, SLOT (doResizeHint()));
    15581575                break;
    15591576            }
     
    15821599            {
    15831600                QKeyEvent *ke = (QKeyEvent *) e;
    1584                 if (ke->key() == Qt::Key_Escape && !(ke->state() & Qt::KeyboardModifierMask))
     1601                if (ke->key() == Qt::Key_Escape && (ke->modifiers() == Qt::NoModifier))
    15851602                    if (mMainWnd->menuBar()->hasFocus())
    15861603                        setFocus();
     
    15921609    }
    15931610
    1594     return Q3ScrollView::eventFilter (watched, e);
     1611    return QAbstractScrollArea::eventFilter (watched, e);
    15951612}
    15961613
     
    25032520                processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL +
    25042521                                                QChar (ch).upper().unicode()),
    2505                                            mMainWnd->menuBar());
     2522                                           mMainWnd->menuBar()->actions());
    25062523        }
    25072524        delete[] list;
     
    25212538            {
    25222539                QChar c = QString::fromLocal8Bit (&ch, 1) [0];
    2523 #warning port me
    2524 //                processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL +
    2525 //                                                c.upper().unicode()),
    2526 //                                           mMainWnd->menuBar());
     2540                processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL +
     2541                                                         c.toUpper().unicode()),
     2542                                           mMainWnd->menuBar()->actions());
    25272543            }
    25282544        }
    25292545#elif defined (Q_WS_MAC)
    2530 #warning port me
    2531 //        if (aUniKey && aUniKey [0] && !aUniKey [1])
    2532 //            processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL +
    2533 //                                                     QChar (aUniKey [0]).upper().unicode()),
    2534 //                                       mMainWnd->menuBar());
     2546        if (aUniKey && aUniKey [0] && !aUniKey [1])
     2547            processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL +
     2548                                                     QChar (aUniKey [0]).upper().unicode()),
     2549                                       mMainWnd->menuBar()->actions());
    25352550
    25362551        /* Don't consider the hot key as pressed since the guest never saw
     
    25852600bool VBoxConsoleView::mouseEvent (int aType, const QPoint &aPos,
    25862601                                  const QPoint &aGlobalPos, Qt::ButtonState aButton,
    2587                                   Qt::ButtonState aState, Qt::ButtonState aStateAfter,
     2602                                  Qt::MouseButtons aButtons, Qt::KeyboardModifiers aModifiers,
    25882603                                  int aWheelDelta, Qt::Orientation aWheelDir)
    25892604{
     
    25912606    char buf [256];
    25922607    sprintf (buf,
    2593              "MOUSE: type=%03d x=%03d y=%03d btn=%03d st=%08X stAfter=%08X "
     2608             "MOUSE: type=%03d x=%03d y=%03d btn=%03d btns=%08X mod=%08X "
    25942609             "wdelta=%03d wdir=%03d",
    2595              aType, aPos.x(), aPos.y(), aButton, aState, aStateAfter,
     2610             aType, aPos.x(), aPos.y(), aButton, aButtons, aModifiers,
    25962611             aWheelDelta, aWheelDir);
    25972612    mMainWnd->statusBar()->message (buf);
    25982613#else
    25992614    Q_UNUSED (aButton);
    2600     Q_UNUSED (aState);
     2615    Q_UNUSED (aModifiers);
    26012616#endif
    26022617
    26032618    int state = 0;
    2604     if (aStateAfter & Qt::LeftButton)
     2619    if (aButtons & Qt::LeftButton)
    26052620        state |= KMouseButtonState_LeftButton;
    2606     if (aStateAfter & Qt::RightButton)
     2621    if (aButtons & Qt::RightButton)
    26072622        state |= KMouseButtonState_RightButton;
    2608     if (aStateAfter & Qt::MidButton)
     2623    if (aButtons & Qt::MidButton)
    26092624        state |= KMouseButtonState_MiddleButton;
    26102625
     
    27842799            if (hasFocus() &&
    27852800                (aType == QEvent::MouseButtonRelease &&
    2786                  !aStateAfter))
     2801                 aButtons == Qt::NoButton))
    27872802            {
    27882803                if (isPaused())
     
    28442859                    mPausedShot = QPixmap::fromImage (shot);
    28452860                    /* fully repaint to pick up mPausedShot */
    2846                     viewport()->repaint();
     2861                    repaint();
    28472862                }
    28482863            }
     
    29132928            {
    29142929                int pw = pm.width(), ph = pm.height();
    2915                 resizeContents (pw, ph);
     2930                viewport()->resize (pw, ph);
    29162931                updateGeometry();
    29172932                setMaximumSize (sizeHint());
     
    29252940                 * on the next event loop iteration. currently disabled.
    29262941                 * updateContents(); */
    2927                 repaintContents (false);
     2942                viewport()->repaint();
    29282943            }
    29292944        }
     
    29332948    else
    29342949#endif
    2935         repaintContents (false);
    2936 }
    2937 
    2938 void VBoxConsoleView::viewportPaintEvent (QPaintEvent *pe)
     2950        viewport()->repaint();
     2951}
     2952
     2953void VBoxConsoleView::resizeEvent (QResizeEvent *)
     2954{
     2955    updateSliders();
     2956}
     2957
     2958void VBoxConsoleView::paintEvent (QPaintEvent *pe)
    29392959{
    29402960#if defined (VBOX_GUI_USE_REFRESH_TIMER)
    2941     if (mode == VBoxDefs::TimerMode)
    2942     {
    2943         if (!pm.isNull())
    2944         {
    2945             /* draw a part of vbuf */
    2946             const QRect &r = pe->rect();
    2947 #warning port me
     2961#warning "port me: Is this needed anymore?"
     2962//    if (mode == VBoxDefs::TimerMode)
     2963//    {
     2964//        if (!pm.isNull())
     2965//        {
     2966//            /* draw a part of vbuf */
     2967//            const QRect &r = pe->rect();
    29482968//            ::bitBlt (viewport(), r.x(), r.y(),
    29492969//                      &pm, r.x() + contentsX(), r.y() + contentsY(),
    29502970//                      r.width(), r.height(),
    29512971//                      CopyROP, TRUE);
    2952         }
    2953         else
    2954         {
    2955             viewport()->erase (pe->rect());
    2956         }
    2957     }
    2958     else
     2972//        }
     2973//        else
     2974//        {
     2975//            viewport()->erase (pe->rect());
     2976//        }
     2977//    }
     2978//    else
    29592979#endif
    29602980    {
     
    31183138 *  is found, activates it and returns true. Otherwise returns false.
    31193139 */
    3120 bool VBoxConsoleView::processHotKey (const QKeySequence &key,  QMenuData *data)
    3121 {
    3122     if (!data) return false;
    3123 
    3124     /*
    3125      *  Note: below, we use the internal class QMenuItem, that is subject
    3126      *  to change w/o notice... (the alternative would be to explicitly assign
    3127      *  specific IDs to all popup submenus in VBoxConsoleWnd and then
    3128      *  look through its children in order to find a popup with a given ID,
    3129      *  which is unconvenient).
    3130      */
    3131 
    3132 #warning port me
    3133 //    for (uint i = 0; i < data->count(); i++)
    3134 //    {
    3135 //        int id = data->idAt (i);
    3136 //        QMenuItem *item = data->findItem (id);
    3137 //        if (item->popup())
    3138 //        {
    3139 //            if (processHotKey (key, item->popup()))
    3140 //                return true;
    3141 //        }
    3142 //        else
    3143 //        {
    3144 //            QStringList list = QStringList::split ("\tHost+", data->text (id));
    3145 //            if (list.count() == 2)
    3146 //            {
    3147 //                if (key.matches (QKeySequence (list[1])) == Identical)
    3148 //                {
    3149 //                    /*
    3150 //                     *  we asynchronously post a special event instead of calling
    3151 //                     *  data->activateItemAt (i) directly, to let key presses
    3152 //                     *  and releases be processed correctly by Qt first.
    3153 //                     *  Note: we assume that nobody will delete the menu item
    3154 //                     *  corresponding to the key sequence, so that the pointer to
    3155 //                     *  menu data posted along with the event will remain valid in
    3156 //                     *  the event handler, at least until the main window is closed.
    3157 //                     */
    3158 //
    3159 //                    QApplication::postEvent (this,
    3160 //                                             new ActivateMenuEvent (data, i));
    3161 //                    return true;
    3162 //                }
    3163 //            }
    3164 //        }
    3165 //    }
     3140bool VBoxConsoleView::processHotKey (const QKeySequence &key, const QList<QAction*>& data)
     3141{
     3142    foreach (QAction *pAction, data)
     3143    {
     3144        if (QMenu *menu = pAction->menu())
     3145            return processHotKey (key, menu->actions());
     3146
     3147        QStringList list = pAction->text().split ("\tHost+");
     3148        if (list.count() == 2)
     3149        {
     3150            if (key.matches (QKeySequence (list[1])) == QKeySequence::ExactMatch)
     3151            {
     3152                /*
     3153                 *  we asynchronously post a special event instead of calling
     3154                 *  pAction->trigger() directly, to let key presses and
     3155                 *  releases be processed correctly by Qt first. Note: we
     3156                 *  assume that nobody will delete the menu item corresponding
     3157                 *  to the key sequence, so that the pointer to menu data
     3158                 *  posted along with the event will remain valid in the event
     3159                 *  handler, at least until the main window is closed.
     3160                 */
     3161                QApplication::postEvent (this,
     3162                                         new ActivateMenuEvent (pAction));
     3163                return true;
     3164            }
     3165        }
     3166    }
    31663167
    31673168    return false;
     
    36763677    }
    36773678}
     3679
     3680int VBoxConsoleView::contentsWidth() const
     3681{
     3682    return mFrameBuf->width();
     3683}
     3684
     3685int VBoxConsoleView::contentsHeight() const
     3686{
     3687    return mFrameBuf->height();
     3688}
     3689
     3690void VBoxConsoleView::updateSliders()
     3691{
     3692    QSize p = viewport()->size();
     3693    QSize m = maximumViewportSize();
     3694
     3695    QSize v = QSize (mFrameBuf->width(), mFrameBuf->height());
     3696    /* no scroll bars needed */
     3697    if (m.expandedTo(v) == m)
     3698        p = m;
     3699
     3700    horizontalScrollBar()->setRange(0, v.width() - p.width());
     3701    verticalScrollBar()->setRange(0, v.height() - p.height());
     3702    horizontalScrollBar()->setPageStep(p.width());
     3703    verticalScrollBar()->setPageStep(p.height());
     3704}
     3705
  • TabularUnified trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp

    r7565 r7590  
    680680
    681681    console = new VBoxConsoleView (this, cconsole, mode,
    682                                    centralWidget(), "console");
     682                                   centralWidget());
    683683
    684684    activateUICustomizations();
     
    837837    /* set the correct initial machine_state value */
    838838    machine_state = cconsole.GetState();
     839
     840    console->normalizeGeometry (true /* adjustPosition */);
    839841
    840842    updateAppearanceOf (AllStuff);
     
    20912093        foreach (QWidget *w, list)
    20922094        {
    2093             if (w != centralWidget())
     2095            /* todo: The list is now recursive. So think about a better way to
     2096             * prevent the childrens of the centralWidget to be hidden */
     2097            if (w != centralWidget() &&
     2098                w != console &&
     2099                w != console->viewport())
    20942100            {
    20952101                if (!w->isHidden())
     
    21152121        centralWidget()->setEraseColor (Qt::black);
    21162122        console_style = console->frameStyle();
    2117         console->setFrameStyle (Q3Frame::NoFrame);
     2123        console->setFrameStyle (QFrame::NoFrame);
    21182124        console->setMaximumSize (scrGeo.size());
    2119 #warning port me
    2120 /*        console->setVScrollBarMode (Q3ScrollView::AlwaysOff);*/
    2121 /*        console->setHScrollBarMode (Q3ScrollView::AlwaysOff);*/
     2125        console->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
     2126        console->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
    21222127
    21232128        /* Going fullscreen */
     
    22042209        console->setFrameStyle (console_style);
    22052210        console->setMaximumSize (console->sizeHint());
    2206 #warning port me
    2207 /*        console->setVScrollBarMode (Q3ScrollView::Auto);*/
    2208 /*        console->setHScrollBarMode (Q3ScrollView::Auto);*/
     2211        console->setHorizontalScrollBarPolicy (Qt::ScrollBarAsNeeded);
     2212        console->setVerticalScrollBarPolicy (Qt::ScrollBarAsNeeded);
    22092213
    22102214        /* Show everything hidden when going fullscreen. */
  • TabularUnified trunk/src/VBox/Frontends/VirtualBox4/src/VBoxProblemReporter.cpp

    r7447 r7590  
    15071507            "operation. The currently assigned host key is shown on the status bar "
    15081508            "at the bottom of the Virtual Machine window, next to the&nbsp;"
    1509             "<img src=hostkey_16px.png/>&nbsp;icon. This icon, together "
     1509            "<img src=:/hostkey_16px.png/>&nbsp;icon. This icon, together "
    15101510            "with the mouse icon placed nearby, indicate the current keyboard "
    15111511            "and mouse capture state."
     
    15401540            "operation. The currently assigned host key is shown on the status bar "
    15411541            "at the bottom of the Virtual Machine window, next to the&nbsp;"
    1542             "<img src=hostkey_16px.png/>&nbsp;icon. This icon, together "
     1542            "<img src=:/hostkey_16px.png/>&nbsp;icon. This icon, together "
    15431543            "with the mouse icon placed nearby, indicate the current keyboard "
    15441544            "and mouse capture state."
     
    15811581                "</p>"
    15821582                "<p>The mouse icon on the status bar will look like&nbsp;"
    1583                 "<img src=mouse_seamless_16px.png/>&nbsp;to inform you that mouse "
     1583                "<img src=:/mouse_seamless_16px.png/>&nbsp;to inform you that mouse "
    15841584                "pointer integration is supported by the guest OS and is "
    15851585                "currently turned on."
     
    17001700            "You can go back to windowed mode at any time by pressing "
    17011701            "<b>%1</b>. Note that the <i>Host</i> key is currently "
    1702             "defined as <b>%1</b>.</p>"
     1702            "defined as <b>%2</b>.</p>"
    17031703            "<p>Note that the main menu bar is hidden in fullscreen mode. You "
    17041704            "can access it by pressing <b>Host+Home</b>.</p>")
     
    17221722            "You can go back to windowed mode at any time by pressing "
    17231723            "<b>%1</b>. Note that the <i>Host</i> key is currently "
    1724             "defined as <b>%1</b>.</p>"
     1724            "defined as <b>%2</b>.</p>"
    17251725            "<p>Note that the main menu bar is hidden in seamless mode. You "
    17261726            "can access it by pressing <b>Host+Home</b>.</p>")
Note: See TracChangeset for help on using the changeset viewer.

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