cursorShapeMigration.patch

Anonymous, 06/26/2008 11:39 PM

Download (14.1 KB)

 
b/libyzis/view.cpp Thu Jun 26 15:49:27 2008 -0500
71 71
          m_drawBuffer(),
72 72
          mPreviousChars(""),mLastPreviousChars(""),
73 73
          mainCursor(this), scrollCursor(this), workCursor(this), mVisualCursor(this), keepCursor(this),
74
		  mCursorShape(YViewIface::CursorHidden),
74 75
          id(nextId++)
75 76
{
76 77
    dbg().SPrintf("YView( %s, cols=%d, lines=%d )", qp(_b->toString()), cols, lines );
......
120 121
    opt_schema = getLocalIntegerOption( "schema" );
121 122
    opt_list = getLocalBooleanOption( "list" );
122 123
    opt_listchars = getLocalMapOption( "listchars" );
124

  
125
	guiCursorChanged(mCursorShape);
123 126

  
124 127
    abortPaintEvent();
125 128
}
......
292 295
void YView::updateMode()
293 296
{
294 297
    QString mode;
298
	YMode::ModeType mt;
295 299

  
296 300
    mode = currentMode()->toString();
301
	mt = currentMode()->modeType();
302

  
303
	YViewIface::CursorShape newCursorShape = YViewIface::CursorHidden;
304

  
305
	switch(mt) {
306
		case YMode::ModeInsert :
307
			setCursorShape(YViewIface::CursorVbar);
308
			break;
309
		case YMode::ModeReplace :
310
			setCursorShape(YViewIface::CursorHbar);
311
			break;
312
		case YMode::ModeIntro :
313
		case YMode::ModeEx :
314
		case YMode::ModeSearch :
315
		case YMode::ModeSearchBackward :
316
			setCursorShape(YViewIface::CursorHidden);
317
			break;
318
		case YMode::ModeCompletion :
319
			break;
320
		case YMode::ModeCommand :
321
		case YMode::ModeVisual :
322
		case YMode::ModeVisualLine :
323
		case YMode::ModeVisualBlock :
324
			setCursorShape(YViewIface::CursorFilledRect);
325
			break;
326
		default:
327
			break;
328
	}
329

  
297 330
    if (isRecording())
298 331
        mode += _(" { Recording }");
299 332

  
......
1640 1673
    return sel.clip( YInterval(scrollCursor.screen(), bottomRight) );
1641 1674
}
1642 1675

  
1676
YViewIface::CursorShape YView::cursorShape() const
1677
{
1678
	return mCursorShape;
1679
}
1680

  
1681
void YView::setCursorShape( YViewIface::CursorShape cs )
1682
{
1683
	if(cs != mCursorShape)
1684
	{
1685
		mCursorShape = cs;
1686
		guiCursorChanged(mCursorShape);
1687
		guiUpdateCursor();
1688
	}
1689
}
1690

  
1643 1691
void YView::setPaintAutoCommit( bool enable )
1644 1692
{
1645 1693
    if ( enable ) {
b/libyzis/view.h Thu Jun 26 15:49:27 2008 -0500
818 818
     */
819 819
    YSelection clipSelection( const YSelection& sel ) const;
820 820

  
821
    /**
822
     * @return the cursors current shape
823
     */
824
    YViewIface::CursorShape cursorShape() const;
825

  
826
    /**
827
     * @param cs the cursor shape to assign to this view
828
     */
829
    void setCursorShape( YViewIface::CursorShape cs );
830

  
821 831
protected:
822 832

  
823 833
    void setupKeys();
......
844 854
     * The buffer we depend on
845 855
     */
846 856
    YBuffer *mBuffer;
857

  
858
    /**
859
     * The Cursor Shape
860
     */
861
    YViewIface::CursorShape mCursorShape;
847 862

  
848 863
    /**
849 864
      * This is the main cursor, the one which is displayed
b/libyzis/viewiface.h Thu Jun 26 15:49:27 2008 -0500
46 46
{
47 47
public:
48 48

  
49
    enum CursorShape {
50
        CursorFilledRect,
51
        CursorVbar,
52
        CursorHbar,
53
        CursorFrameRect,
54
        CursorHidden,
55
    };
56

  
49 57
    //-------------------------------------------------------
50 58
    //                GUI Notifications
51 59
    //-------------------------------------------------------
......
60 68
     * Status bar feedback is handled by YView.
61 69
     */
62 70
    virtual void guiUpdateCursor() = 0;
71

  
72

  
73
    /** Tells the GUI that cursor has changed
74
     */
75
    virtual void guiCursorChanged(YViewIface::CursorShape)
76
    {}
63 77

  
64 78
    /** Called when buffer's filename has changed.
65 79
     * Basic feedback is already handled by YView,
b/qyzis/qycursor.cpp Thu Jun 26 15:49:27 2008 -0500
31 31
#define dbg() yzDebug("QYCursor")
32 32
#define err() yzError("QYCursor")
33 33

  
34
QYCursor::QYCursor( QYView * view, QYEdit* edit, CursorShape shape )
34
QYCursor::QYCursor( QYView * view, QYEdit* edit, YViewIface::CursorShape shape )
35 35
        : QWidget( edit )
36 36
{
37 37
    mView = view;
......
49 49
QYCursor::~QYCursor()
50 50
{}
51 51

  
52
QYCursor::CursorShape QYCursor::shape() const
52
YViewIface::CursorShape QYCursor::shape() const
53 53
{
54 54
    return mCursorShape;
55 55
}
56
void QYCursor::setCursorShape( CursorShape shape )
56
void QYCursor::setCursorShape( YViewIface::CursorShape shape )
57 57
{
58 58
    if ( shape == mCursorShape )
59 59
        return ;
60 60
    mCursorShape = shape;
61 61
    int w = parentWidget()->fontMetrics().maxWidth();
62 62
    int h = parentWidget()->fontMetrics().lineSpacing();
63
    if ( mCursorShape == CursorVbar )
63
    if ( mCursorShape == YViewIface::CursorVbar )
64 64
        w = 2;
65 65
    resize( w, h );
66 66
}
......
100 100

  
101 101
    QPainter p( this );
102 102
    QRect r = rect();
103
    CursorShape s = shape();
103
	YViewIface::CursorShape s = shape();
104 104
    deepdbg() << "paintEvent(): shape=" << s << endl;
105 105
    switch ( s ) {
106
    case CursorFilledRect :
106
		case YViewIface::CursorFilledRect :
107 107
        p.setPen( cbg );
108 108
        p.setBackground( cfg );
109 109
        // erase with cell foreground
......
112 112
        p.drawText( rect(), cell.c );
113 113
        break;
114 114

  
115
    case CursorFrameRect :
115
		case YViewIface::CursorFrameRect :
116 116
        p.setPen( cfg );
117 117
        p.setBackground( cbg );
118 118
        // erase with cell background
......
125 125
        p.drawRect( r );
126 126
        break;
127 127

  
128
    case CursorVbar :
128
		case YViewIface::CursorVbar :
129 129
        r.setWidth( 2 );
130 130
        p.fillRect( r, QBrush(cfg) );
131 131
        break;
132 132

  
133
    case CursorHbar:
133
		case YViewIface::CursorHbar:
134 134
        // erase with cell background
135 135
        p.eraseRect( r );
136 136
        // paint character with cell foreground
......
139 139
        p.fillRect( r, QBrush(cfg) );
140 140
        break;
141 141

  
142
    case CursorHidden:
142
		case YViewIface::CursorHidden:
143 143
        // erase with cell background
144 144
        p.eraseRect( r );
145 145
        // paint character with cell foreground
......
148 148
    }
149 149
}
150 150

  
151
YDebugStream& operator<<( YDebugStream& out, const QYCursor::CursorShape & shape )
151
YDebugStream& operator<<( YDebugStream& out, const YViewIface::CursorShape & shape )
152 152
{
153 153
    switch ( shape ) {
154
    case QYCursor::CursorFilledRect : out << "CursorFilledRect"; break;
155
    case QYCursor::CursorVbar : out << "CursorVbar"; break;
156
    case QYCursor::CursorHbar : out << "CursorHbar"; break;
157
    case QYCursor::CursorFrameRect : out << "CursorFrameRect"; break;
158
    case QYCursor::CursorHidden : out << "CursorHidden"; break;
154
    case YViewIface::CursorFilledRect : out << "CursorFilledRect"; break;
155
    case YViewIface::CursorVbar : out << "CursorVbar"; break;
156
    case YViewIface::CursorHbar : out << "CursorHbar"; break;
157
    case YViewIface::CursorFrameRect : out << "CursorFrameRect"; break;
158
    case YViewIface::CursorHidden : out << "CursorHidden"; break;
159 159
    }
160 160
    return out;
161 161
}
b/qyzis/qycursor.h Thu Jun 26 15:49:27 2008 -0500
20 20
#ifndef QYZISCURSOR_H
21 21
#define QYZISCURSOR_H
22 22

  
23
#include "viewiface.h"
24

  
23 25
#include <QWidget>
24 26

  
25 27
class YDebugStream;
......
31 33
    Q_OBJECT
32 34

  
33 35
public :
34
    enum CursorShape {
35
        CursorFilledRect,
36
        CursorVbar,
37
        CursorHbar,
38
        CursorFrameRect,
39
        CursorHidden,
40
    };
41 36

  
42
    QYCursor( QYView * view, QYEdit* parent, CursorShape shape );
37
    QYCursor( QYView * view, QYEdit* parent, YViewIface::CursorShape shape );
43 38
    virtual ~QYCursor();
44 39

  
45
    void setCursorShape( CursorShape shape );
46
    CursorShape shape() const;
40
    void setCursorShape( YViewIface::CursorShape shape );
41
    YViewIface::CursorShape shape() const;
47 42

  
48 43

  
49 44
protected :
50 45
    virtual void paintEvent( QPaintEvent* pe );
51 46

  
52 47
private :
53
    CursorShape mCursorShape;
48
    YViewIface::CursorShape mCursorShape;
54 49
    QYEdit* mEdit;
55 50
    QYView* mView;
56 51

  
57 52
};
58 53

  
59
YDebugStream& operator<<( YDebugStream& out, const QYCursor::CursorShape & shape );
54
YDebugStream& operator<<( YDebugStream& out, const YViewIface::CursorShape & shape );
60 55

  
61 56
#endif
62 57

  
b/qyzis/qyedit.cpp Thu Jun 26 15:49:27 2008 -0500
63 63
    /* show an edit cursor */
64 64
    QWidget::setCursor( Qt::IBeamCursor );
65 65

  
66
    mCursor = new QYCursor( mView, this, QYCursor::CursorFilledRect );
66
    mCursor = new QYCursor( mView, this, YViewIface::CursorFilledRect );
67

  
68
	mPreviousCursorShape = view->cursorShape();
67 69

  
68 70
    initKeys();
69 71
}
......
108 110
    return translateRealToPosition( p, ceil ) + mView->getScreenPosition();
109 111
}
110 112

  
111
QYCursor::CursorShape QYEdit::cursorShape()
113
void QYEdit::setCursorShape( YViewIface::CursorShape cs )
112 114
{
113
    QYCursor::CursorShape shape;
114
    YMode::ModeType m = mView->modePool()->currentType();
115
    deepdbg() << "cursorShape(): mode=" << m << endl;
116
    shape = mCursor->shape();
117
    if ( ! hasFocus() ) {
118
        if (mView->mCommandLine->hasFocus()) {
119
            // command line has focus
120
            shape = QYCursor::CursorHidden;
121
        } else {
122
            // the widget no longer has focus
123
            shape = QYCursor::CursorFrameRect;
124
        }
125
    } else {
126
        switch ( m ) {
127
        case YMode::ModeInsert :
128
            shape = QYCursor::CursorVbar;
129
            break;
130
        case YMode::ModeReplace :
131
            shape = QYCursor::CursorHbar;
132
            break;
133
        case YMode::ModeIntro:
134
        case YMode::ModeEx:
135
        case YMode::ModeSearch:
136
        case YMode::ModeSearchBackward:
137
            shape = QYCursor::CursorHidden;
138
            break;
139
        case YMode::ModeCompletion :
140
            // do not change it
141
            break;
142
        case YMode::ModeCommand:
143
        case YMode::ModeVisual:
144
        case YMode::ModeVisualLine:
145
        case YMode::ModeVisualBlock:
146
            shape = QYCursor::CursorFilledRect;
147
            break;
148
        }
149
    }
150

  
151
    deepdbg() << "cursorShape(), cursorShape=" << shape << endl;
152
    return shape;
115
	mCursor->setCursorShape( cs );
153 116
}
154 117

  
155 118
void QYEdit::updateCursor()
156 119
{
157
    mCursor->setCursorShape( cursorShape() );
158 120
    mCursor->update();
159 121
}
160 122

  
......
292 254
void QYEdit::focusInEvent ( QFocusEvent * )
293 255
{
294 256
    dbg() << "focusInEvent() for " << mView->myBuffer()->fileNameShort() << endl;
257
	mView->setCursorShape( mPreviousCursorShape );
295 258
    YSession::self()->setCurrentView( mView );
296 259
    updateCursor();
297 260
}
298 261
void QYEdit::focusOutEvent ( QFocusEvent * )
299 262
{
300 263
    dbg() << "focusOutEvent() for " << mView->myBuffer()->fileNameShort() << endl;
264
	mPreviousCursorShape = mView->cursorShape();
265
	if(mPreviousCursorShape != YViewIface::CursorHidden) {
266
		mView->setCursorShape( YViewIface::CursorFrameRect );
267
	}
301 268
    updateCursor();
302 269
}
303 270

  
......
333 300
    if ( !mCursor->isVisible() )
334 301
        mCursor->show();
335 302

  
303
	mCursor->update();
336 304
    // need for InputMethod (OverTheSpot)
337 305
    // setMicroFocusHint( mCursor->x(), mCursor->y(), mCursor->width(), mCursor->height() );
338 306
}
......
480 448

  
481 449
void QYEdit::registerModifierKeys( const QString& keys )
482 450
{
451
	Q_UNUSED(keys)
483 452
    /*
484 453
    KAction* k = new KAction( "", KShortcut( keysToShortcut( keys ) ), signalMapper, SLOT( map() ), actionCollection, keys.ascii() );
485 454
    signalMapper->setMapping( k, keys );
......
487 456
}
488 457
void QYEdit::unregisterModifierKeys( const QString& keys )
489 458
{
459
	Q_UNUSED(keys)
490 460
    /*
491 461
    QByteArray ke = keys.toUtf8();
492 462
    KAction* k = actionCollection->action( ke.data() );
b/qyzis/qyedit.h Thu Jun 26 15:49:27 2008 -0500
28 28
#include "drawbuffer.h"
29 29
#include "action.h"
30 30
#include "keys.h"
31
#include "view.h"
31 32

  
32 33
/* Qt */
33 34
#include <qpainter.h>
......
63 64
    void setCursor(int c, int l);
64 65
    void scroll( int dx, int dy );
65 66

  
66
    /** Return a cursor shape according to the current mode and focus */
67
    QYCursor::CursorShape cursorShape();
68

  
69 67
    /** Adjust the cursor shape.
70 68
      *
71 69
      * Set the cursor shape returned bye cursorShape() to the current cursor.
72 70
      */
73 71
    void updateCursor();
72

  
73
    void setCursorShape( YViewIface::CursorShape cs );
74 74

  
75 75
    /** Called when the mode has changed.
76 76
     *
......
152 152

  
153 153
    static QMap<int, YKey> keys;
154 154

  
155
    YViewIface::CursorShape mPreviousCursorShape;
156

  
155 157
    friend class QYCursor;
156 158
    friend class QYView;
157 159
};
b/qyzis/qyview.cpp Thu Jun 26 15:49:27 2008 -0500
86 86

  
87 87
    mEdit->show();
88 88
    mStatusBar->show();
89
    mCommandLine->show();
89 90
    mEdit->setFocus();
90 91
    setFocusProxy( mEdit );
91 92
    mVScroll->setMaximum( myBuffer()->lineCount() - 1 );
......
293 294
    mEdit->setCursor(viewCursor().screenX(), viewCursor().screenY());
294 295
}
295 296

  
297
void QYView::guiCursorChanged(YViewIface::CursorShape cs)
298
{
299
	dbg() << "guiCursorChanged( " << cs << " )";
300
	mEdit->setCursorShape(cs);
301
}
302

  
296 303
void QYView::guiUpdateMode()
297 304
{
298
    mEdit->updateCursor();
299 305
}
300 306

  
301 307
void QYView::guiHighlightingChanged()
b/qyzis/qyview.h Thu Jun 26 15:49:27 2008 -0500
87 87
    virtual void guiUpdateFileName();
88 88
    virtual void guiUpdateCursor();
89 89
    virtual void guiUpdateMode();
90
    virtual void guiCursorChanged(YViewIface::CursorShape cs);
90 91
    void guiHighlightingChanged();
91 92

  
92 93
protected: