55
66namespace 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
5287void 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
65107void 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
89131void 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
243288void 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
0 commit comments