Skip to content

Commit 1f36007

Browse files
committed
TODO Fold
1 parent 255c269 commit 1f36007

File tree

9 files changed

+108
-80
lines changed

9 files changed

+108
-80
lines changed

src/gui/cmdline/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ set(SOURCES
1212
blockdisplay.cpp
1313
linemodel.cpp
1414
extcmdlinewidget.cpp
15-
qrichlineedit.cpp
1615
)
1716

1817
add_library(extcmdline STATIC ${SOURCES})

src/gui/cmdline/extcmdlinewidget.cpp

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@
55

66
namespace NeovimQt { namespace Cmdline {
77

8-
ExtCmdlineWidget::ExtCmdlineWidget(ShellWidget* parent)
8+
ExtCmdlineWidget::ExtCmdlineWidget(ShellWidget& parent)
99
{
10-
setParent(parent);
10+
setParent(&parent);
1111
setVisible(false);
1212

13-
m_cmdTextBox = new QRichLineEdit();
13+
m_cmdTextBoxFrame = new QFrame();
14+
m_cmdTextBoxFrame->setFrameShape(QFrame::StyledPanel);
15+
m_cmdTextBoxFrame->setFrameShadow(QFrame::Raised);
16+
QVBoxLayout* frameLayout = new QVBoxLayout(m_cmdTextBoxFrame);
17+
18+
m_cmdTextBox = new ShellWidget();
19+
frameLayout->addWidget(m_cmdTextBox);
20+
1421
m_cmdBlockText = new BlockDisplay();
22+
m_cmdTextBox->setIgnoreFocus(true);
1523

1624
m_vLayout = new QVBoxLayout();
1725
m_vLayout->addWidget(m_cmdBlockText);
18-
m_vLayout->addWidget(m_cmdTextBox);
26+
m_vLayout->addWidget(m_cmdTextBoxFrame);
1927
setLayout(m_vLayout);
2028

2129
// The size of this widget must change when text content changes.
@@ -31,6 +39,10 @@ void ExtCmdlineWidget::handleCmdlineShow(
3139
int indent,
3240
int level)
3341
{
42+
ShellWidget* parentShellWidget{ static_cast<ShellWidget*>(parentWidget()) };
43+
44+
m_cmdTextBox->CopyCursorStyle(parentShellWidget->getCursor());
45+
3446
QString cmdlineContent;
3547

3648
LineModel lineModel{ content, pos, firstc, prompt, indent, level };
@@ -41,12 +53,35 @@ void ExtCmdlineWidget::handleCmdlineShow(
4153
m_model[level - 1] = std::move(lineModel);
4254
}
4355

44-
m_cmdTextBox->setText(m_model.last().getPromptText());
56+
m_cmdTextBox->clearShell();
57+
58+
const QString& text{ m_model.last().getPromptText() };
59+
60+
auto getShellSize = [&]() noexcept
61+
{
62+
const int cellSize{ m_cmdTextBox->cellSize().width() };
63+
const int columns{ m_cmdTextBox->size().width() / cellSize };
64+
const int rows{ text.size() / columns + 1 };
65+
66+
return QSize{ std::max(columns, 1), rows};
67+
};
68+
69+
const QSize cmdSize{ getShellSize() };
70+
m_cmdTextBox->resizeShell(cmdSize);
71+
72+
for (int i=0;i<cmdSize.height();i++) {
73+
int startPos = i * cmdSize.width();
74+
QString row{ text.mid(startPos, cmdSize.width()) };
75+
m_cmdTextBox->put(row, i, 0);
76+
}
77+
78+
const int cols{ cmdSize.width() };
79+
80+
m_cmdTextBox->setNeovimCursor(pos / cols, pos % cols + 1);
81+
m_cmdTextBox->update();
4582

4683
updateGeometry();
4784
show();
48-
49-
setCursorPosition(pos);
5085
}
5186

5287
void ExtCmdlineWidget::handleCmdlinePos(
@@ -59,7 +94,14 @@ void ExtCmdlineWidget::handleCmdlinePos(
5994
}
6095

6196
m_model[level - 1].m_position = pos;
62-
setCursorPosition(pos);
97+
Cursor cursor;
98+
//setCursorPosition(pos);
99+
qDebug() << "Handle Cursor Position";
100+
m_cmdTextBox->setNeovimCursor(0, pos);
101+
m_cmdTextBox->resizeShell(1, m_model[level -1].getPromptText().size());
102+
//m_cmdTextBox->setCursorColors(Qt::blue, Qt::red);
103+
//m_cmdTextBox->setCursorStuff();
104+
update();
63105
}
64106

65107
void ExtCmdlineWidget::handleCmdlineSpecialChar(
@@ -83,7 +125,7 @@ void ExtCmdlineWidget::handleCmdlineSpecialChar(
83125
line.m_content.replace(line.m_position, 1, c);
84126
}
85127

86-
m_cmdTextBox->setText(line.getPromptText());
128+
m_cmdTextBox->put(line.getPromptText(),0,0); // FIXME
87129
}
88130

89131
void ExtCmdlineWidget::handleCmdlineHide()
@@ -174,11 +216,11 @@ void ExtCmdlineWidget::setCursorPosition(int pos)
174216
QTextCharFormat fmtInverse;
175217
fmtInverse.setBackground(parentShellWidget->foreground());
176218
fmtInverse.setForeground(parentShellWidget->background());
177-
m_cmdTextBox->setTextFormat({ { posCursorReal, 1, fmtInverse} });
219+
//m_cmdTextBox->setTextFormat({ { posCursorReal, 1, fmtInverse} });
178220

179221
// Ensures ':' is shown when users scrolls full left
180222
if (pos == 0) {
181-
m_cmdTextBox->setCursorPosition(0);
223+
m_cmdTextBox->setNeovimCursor(0,0);
182224
return;
183225
}
184226

@@ -190,7 +232,7 @@ void ExtCmdlineWidget::setCursorPosition(int pos)
190232
if (last_pos <= pos) {
191233
++cursorPositionQt;
192234
}
193-
m_cmdTextBox->setCursorPosition(cursorPositionQt);
235+
m_cmdTextBox->setNeovimCursor(0,cursorPositionQt);
194236

195237
last_pos = pos;
196238
}
@@ -236,14 +278,17 @@ void ExtCmdlineWidget::updatePalette()
236278
m_palette.setColor(QPalette::Text, parentShellWidget->foreground());
237279
m_palette.setColor(QPalette::Background, parentShellWidget->foreground());
238280

239-
m_cmdTextBox->setPalette(m_palette);
240281
m_cmdBlockText->setPalette(m_palette);
282+
283+
m_cmdTextBox->setBackground(parentShellWidget->background());
284+
m_cmdTextBox->setForeground(parentShellWidget->foreground());
285+
m_cmdTextBox->setStyleSheet(".ShellWidget{background-color: red; border: 1px solid black; border-radius: 10px;}");
241286
}
242287

243288
void ExtCmdlineWidget::setFont(const QFont &font)
244289
{
245290
m_cmdBlockText->setFont(font);
246-
m_cmdTextBox->setFont(font);
291+
//m_cmdTextBox->setFont(font);
247292
}
248293

249294
} } // namespace NeovimQt::Cmdline

src/gui/cmdline/extcmdlinewidget.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99

1010
#include "blockdisplay.h"
1111
#include "linemodel.h"
12-
#include "qrichlineedit.h"
1312

1413
namespace NeovimQt { namespace Cmdline {
1514

1615
class ExtCmdlineWidget : public QFrame{
1716
Q_OBJECT
1817

1918
public:
20-
ExtCmdlineWidget(ShellWidget* parent = nullptr);
19+
ExtCmdlineWidget(ShellWidget& parent);
2120

2221
virtual void handleCmdlineShow(
2322
const QVariantList& content,
@@ -59,7 +58,8 @@ class ExtCmdlineWidget : public QFrame{
5958
private:
6059
int getMaxPromptLength() const;
6160

62-
QRichLineEdit* m_cmdTextBox;
61+
QFrame* m_cmdTextBoxFrame;
62+
ShellWidget* m_cmdTextBox;
6363
BlockDisplay* m_cmdBlockText;
6464

6565
QVBoxLayout* m_vLayout;

src/gui/cmdline/qrichlineedit.cpp

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/gui/cmdline/qrichlineedit.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/gui/shell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private slots:
221221
/// GuiScrollBar last known position: used to compute scroll line delta.
222222
int m_lastScrollBarPosition{ 0 };
223223

224-
Cmdline::ExtCmdlineWidget m_cmdlineWidget{ this };
224+
Cmdline::ExtCmdlineWidget m_cmdlineWidget{ *this };
225225
};
226226

227227
class ShellRequestHandler: public QObject, public MsgpackRequestHandler

src/gui/shellwidget/cursor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ class Cursor : public QObject
3535
m_foreground = highlight.GetForegroundColor();
3636
}
3737

38+
void CopyCursorStyle(const Cursor& cursor) noexcept
39+
{
40+
m_background = cursor.GetBackgroundColor();
41+
m_foreground = cursor.GetForegroundColor();
42+
m_shape = cursor.GetShape();
43+
m_percentage = cursor.GetPercentage();
44+
m_styleEnabled = true; // FIXME rebase...
45+
}
46+
3847
void SetStyle(Shape cursorShape, uint8_t cellPercentage) noexcept
3948
{
4049
m_shape = cursorShape;

src/gui/shellwidget/shellwidget.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "helpers.h"
77

88
ShellWidget::ShellWidget(QWidget* parent)
9-
: QWidget(parent)
9+
: QFrame(parent)
1010
{
1111
setAttribute(Qt::WA_OpaquePaintEvent);
1212
setAttribute(Qt::WA_KeyCompression, false);
@@ -155,7 +155,7 @@ void ShellWidget::paintNeovimCursorBackground(QPainter& p, QRect cellRect) noexc
155155
}
156156

157157
// If the window does not have focus, draw an outline around the cursor cell.
158-
if (!hasFocus()) {
158+
if (!m_ignoreFocus && !hasFocus()) {
159159
QRect noFocusCursorRect{ cellRect };
160160
noFocusCursorRect.adjust(-1, -1, -1, -1);
161161

@@ -177,7 +177,7 @@ void ShellWidget::paintNeovimCursorForeground(
177177
QChar character) noexcept
178178
{
179179
// No focus: cursor is outline with default foreground color.
180-
if (!hasFocus()) {
180+
if (!m_ignoreFocus && !hasFocus()) {
181181
return;
182182
}
183183

@@ -359,6 +359,11 @@ QSize ShellWidget::sizeHint() const
359359
m_cellSize.height()*m_contents.rows());
360360
}
361361

362+
void ShellWidget::resizeShell(QSize size) noexcept
363+
{
364+
resizeShell(size.height(), size.width());
365+
}
366+
362367
void ShellWidget::resizeShell(int n_rows, int n_columns)
363368
{
364369
if (n_rows != rows() || n_columns != columns()) {

src/gui/shellwidget/shellwidget.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#define QSHELLWIDGET2_SHELLWIDGET
33

44
#include <QWidget>
5+
#include <QFrame>
56

67
#include "shellcontents.h"
78
#include "cursor.h"
89

9-
class ShellWidget: public QWidget
10+
class ShellWidget: public QFrame
1011
{
1112
Q_OBJECT
1213
Q_PROPERTY(QColor background READ background WRITE setBackground)
@@ -46,10 +47,34 @@ class ShellWidget: public QWidget
4647

4748
void setBackgroundType(Background type) { m_background = type; }
4849

50+
/// Move the neovim cursor for text insertion and display
51+
void setNeovimCursor(uint64_t col, uint64_t row) noexcept;
52+
53+
const Cursor& getCursor() const noexcept
54+
{
55+
return m_cursor;
56+
}
57+
58+
void CopyCursorStyle(const Cursor& cursor) noexcept
59+
{
60+
m_cursor.CopyCursorStyle(cursor);
61+
}
62+
63+
void setIgnoreFocus(bool ignore) noexcept
64+
{
65+
m_ignoreFocus = ignore;
66+
}
67+
68+
bool getIgnoreFocus() noexcept
69+
{
70+
return m_ignoreFocus;
71+
}
72+
4973
signals:
5074
void shellFontChanged();
5175
void fontError(const QString& msg);
5276
public slots:
77+
void resizeShell(QSize size) noexcept;
5378
void resizeShell(int rows, int columns);
5479
void setSpecial(const QColor& color);
5580
void setBackground(const QColor& color);
@@ -89,9 +114,6 @@ public slots:
89114
/// Get the area filled by the cursor
90115
QRect neovimCursorRect() const noexcept;
91116

92-
/// Move the neovim cursor for text insertion and display
93-
void setNeovimCursor(uint64_t col, uint64_t row) noexcept;
94-
95117
virtual void paintEvent(QPaintEvent *ev) Q_DECL_OVERRIDE;
96118
virtual void resizeEvent(QResizeEvent *ev) Q_DECL_OVERRIDE;
97119

@@ -113,6 +135,8 @@ public slots:
113135
QColor m_spColor;
114136
int m_lineSpace{ 0 };
115137

138+
bool m_ignoreFocus{ false };
139+
116140
Background m_background{ Background::Dark };
117141
};
118142

0 commit comments

Comments
 (0)