- Timestamp:
- Jan 12, 2018 12:29:25 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 120234
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r70539 r70554 341 341 src/logviewer/UIVMLogViewerPanel.h \ 342 342 src/logviewer/UIVMLogViewerSearchPanel.h \ 343 src/logviewer/UIVMLogViewerTextEdit.h \ 343 344 src/logviewer/UIVMLogViewerWidget.h \ 344 345 src/medium/UIMediumDetailsWidget.h \ … … 548 549 src/globals/UIMainEventListener.cpp \ 549 550 src/globals/UIThreadPool.cpp \ 550 src/logviewer/UIVMLogPage.cpp \551 551 src/logviewer/UIVMLogViewerFilterPanel.cpp \ 552 src/logviewer/UIVMLogViewerTextEdit.cpp \ 552 553 src/medium/UIMediumEnumerator.cpp \ 553 554 src/runtime/UIActionPoolRuntime.cpp \ … … 660 661 src/logviewer/UIVMLogViewerPanel.cpp \ 661 662 src/logviewer/UIVMLogViewerSearchPanel.cpp \ 663 src/logviewer/UIVMLogViewerTextEdit.cpp \ 662 664 src/logviewer/UIVMLogViewerWidget.cpp \ 663 665 src/medium/UIMediumDefs.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp
r70549 r70554 28 28 # endif 29 29 # include <QPainter> 30 # include <QPlainTextEdit>31 30 # include <QScrollBar> 32 31 # include <QTextBlock> 33 32 34 33 /* GUI includes: */ 35 # include "QIFileDialog.h"36 # include "QITabWidget.h"37 # include "UIExtraDataManager.h"38 # include "UIIconPool.h"39 # include "UIMessageCenter.h"40 34 # include "UIVMLogPage.h" 41 # include "UIVMLogViewerBookmarksPanel.h" 42 # include "UIVMLogViewerFilterPanel.h" 43 # include "UIVMLogViewerSearchPanel.h" 44 # include "UIToolBar.h" 45 46 /* COM includes: */ 47 # include "CSystemProperties.h" 48 49 # include "VBoxGlobal.h" 35 # include "UIVMLogViewerTextEdit.h" 50 36 51 37 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 52 53 54 /** We use a modified scrollbar style for our QPlainTextEdits to get the55 markings on the scrollbars correctly. The default scrollbarstyle does not56 reveal the height of the pushbuttons on the scrollbar (on either side of it, with arrow on them)57 to compute the marking locations correctly. Thus we turn these push buttons off: */58 const QString verticalScrollBarStyle("QScrollBar:vertical {"59 "border: 1px ridge grey; "60 "margin: 0px 0px 0 0px;}"61 "QScrollBar::handle:vertical {"62 "min-height: 10px;"63 "background: grey;}"64 "QScrollBar::add-line:vertical {"65 "width: 0px;}"66 "QScrollBar::sub-line:vertical {"67 "width: 0px;}");68 69 const QString horizontalScrollBarStyle("QScrollBar:horizontal {"70 "border: 1px ridge grey; "71 "margin: 0px 0px 0 0px;}"72 "QScrollBar::handle:horizontal {"73 "min-height: 10px;"74 "background: grey;}"75 "QScrollBar::add-line:horizontal {"76 "height: 0px;}"77 "QScrollBar::sub-line:horizontal {"78 "height: 0px;}");79 80 class UIIndicatorScrollBar : public QScrollBar81 {82 Q_OBJECT;83 84 public:85 86 UIIndicatorScrollBar(QWidget *parent = 0)87 :QScrollBar(parent)88 {89 setStyleSheet(verticalScrollBarStyle);90 }91 92 void setMarkingsVector(const QVector<float> &vector)93 {94 m_markingsVector = vector;95 }96 97 void clearMarkingsVector()98 {99 m_markingsVector.clear();100 }101 102 protected:103 104 virtual void paintEvent(QPaintEvent *pEvent) /* override */105 {106 QScrollBar::paintEvent(pEvent);107 /* Put a red line to marking position: */108 for (int i = 0; i < m_markingsVector.size(); ++i)109 {110 QPointF p1 = QPointF(0, m_markingsVector[i] * height());111 QPointF p2 = QPointF(width(), m_markingsVector[i] * height());112 113 QPainter painter(this);114 painter.setRenderHint(QPainter::Antialiasing, true);115 painter.setPen(QPen(QColor(255, 0, 0, 75), 1.1f));116 painter.drawLine(p1, p2);117 }118 }119 120 private:121 122 /* Stores the relative (to scrollbar's height) positions of markings,123 where we draw a horizontal line. Values are in [0.0, 1.0]*/124 QVector<float> m_markingsVector;125 };126 127 /* Sub-class QPlainTextEdit for some addtional context menu items: */128 class UIVMLogViewerTextEdit : public QPlainTextEdit129 {130 Q_OBJECT;131 132 signals:133 134 void sigContextMenuBookmarkAction(LogBookmark bookmark);135 136 public:137 UIVMLogViewerTextEdit(QWidget* parent = 0)138 :QPlainTextEdit(parent)139 {140 //setStyleSheet("background-color: rgba(240, 240, 240, 75%) ");141 }142 143 protected:144 145 void contextMenuEvent(QContextMenuEvent *pEvent)146 {147 QMenu *menu = createStandardContextMenu();148 QAction *pAction = menu->addAction(tr("Bookmark"));149 QTextBlock block = cursorForPosition(pEvent->pos()).block();150 m_iContextMenuBookmark.first = block.firstLineNumber();151 m_iContextMenuBookmark.second = block.text();152 153 if (pAction)154 connect(pAction, &QAction::triggered, this, &UIVMLogViewerTextEdit::sltBookmark);155 156 menu->exec(pEvent->globalPos());157 158 if (pAction)159 disconnect(pAction, &QAction::triggered, this, &UIVMLogViewerTextEdit::sltBookmark);160 161 delete menu;162 }163 164 virtual void mousePressEvent(QMouseEvent *pEvent)165 {166 QPlainTextEdit::mousePressEvent(pEvent);167 }168 169 private slots:170 171 void sltBookmark()172 {173 emit sigContextMenuBookmarkAction(m_iContextMenuBookmark);174 }175 176 private:177 178 /* Line number and text at the context menu position */179 LogBookmark m_iContextMenuBookmark;180 };181 38 182 39 … … 184 41 : QIWithRetranslateUI<QWidget>(pParent) 185 42 , m_pMainLayout(0) 186 , m_p PlainTextEdit(0)43 , m_pTextEdit(0) 187 44 , m_tabIndex(tabIndex) 188 45 { … … 197 54 int UIVMLogPage::defaultLogPageWidth() const 198 55 { 199 if (!m_p PlainTextEdit)56 if (!m_pTextEdit) 200 57 return 0; 201 58 202 59 /* Compute a width for 132 characters plus scrollbar and frame width: */ 203 int iDefaultWidth = m_p PlainTextEdit->fontMetrics().width(QChar('x')) * 132 +204 m_p PlainTextEdit->verticalScrollBar()->width() +205 m_p PlainTextEdit->frameWidth() * 2;60 int iDefaultWidth = m_pTextEdit->fontMetrics().width(QChar('x')) * 132 + 61 m_pTextEdit->verticalScrollBar()->width() + 62 m_pTextEdit->frameWidth() * 2; 206 63 207 64 return iDefaultWidth; … … 222 79 m_pMainLayout->setContentsMargins(0, 0, 0, 0); 223 80 224 m_pPlainTextEdit = new UIVMLogViewerTextEdit(this); 225 m_pMainLayout->addWidget(m_pPlainTextEdit); 226 227 m_pPlainTextEdit->setVerticalScrollBar(new UIIndicatorScrollBar()); 228 m_pPlainTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); 229 QScrollBar *pHorizontalScrollBar = m_pPlainTextEdit->horizontalScrollBar(); 230 if (pHorizontalScrollBar) 231 pHorizontalScrollBar->setStyleSheet(horizontalScrollBarStyle); 232 233 #if defined(RT_OS_SOLARIS) 234 /* Use system fixed-width font on Solaris hosts as the Courier family fonts don't render well. */ 235 QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); 236 #else 237 QFont font; 238 font.setFamily("Courier New,courier"); 239 #endif 240 m_pPlainTextEdit->setFont(font); 241 m_pPlainTextEdit->setWordWrapMode(QTextOption::NoWrap); 242 m_pPlainTextEdit->setReadOnly(true); 243 connect(qobject_cast<UIVMLogViewerTextEdit*>(m_pPlainTextEdit), &UIVMLogViewerTextEdit::sigContextMenuBookmarkAction, 81 m_pTextEdit = new UIVMLogViewerTextEdit(this); 82 m_pMainLayout->addWidget(m_pTextEdit); 83 84 connect(qobject_cast<UIVMLogViewerTextEdit*>(m_pTextEdit), &UIVMLogViewerTextEdit::sigContextMenuBookmarkAction, 244 85 this, &UIVMLogPage::sltAddBookmark); 245 86 } … … 247 88 QPlainTextEdit *UIVMLogPage::textEdit() 248 89 { 249 return m_p PlainTextEdit;90 return m_pTextEdit; 250 91 } 251 92 252 93 QTextDocument* UIVMLogPage::document() 253 94 { 254 if (!m_p PlainTextEdit)95 if (!m_pTextEdit) 255 96 return 0; 256 return m_p PlainTextEdit->document();97 return m_pTextEdit->document(); 257 98 } 258 99 … … 297 138 void UIVMLogPage::setTextEdit(const QString &strText) 298 139 { 299 m_p PlainTextEdit->setPlainText(strText);140 m_pTextEdit->setPlainText(strText); 300 141 /* Move the cursor position to end: */ 301 QTextCursor cursor = m_p PlainTextEdit->textCursor();142 QTextCursor cursor = m_pTextEdit->textCursor(); 302 143 cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); 303 m_p PlainTextEdit->setTextCursor(cursor);144 m_pTextEdit->setTextCursor(cursor); 304 145 repaint(); 305 146 } … … 307 148 void UIVMLogPage::markForError() 308 149 { 309 QPalette pal = m_p PlainTextEdit->palette();150 QPalette pal = m_pTextEdit->palette(); 310 151 pal.setColor(QPalette::Base, pal.color(QPalette::Window)); 311 m_p PlainTextEdit->setPalette(pal);152 m_pTextEdit->setPalette(pal); 312 153 } 313 154 314 155 void UIVMLogPage::setScrollBarMarkingsVector(const QVector<float> &vector) 315 156 { 316 if (!m_pPlainTextEdit) 317 return; 318 UIIndicatorScrollBar* scrollBar = qobject_cast<UIIndicatorScrollBar*>(m_pPlainTextEdit->verticalScrollBar()); 319 if (scrollBar) 320 scrollBar->setMarkingsVector(vector); 157 if (!m_pTextEdit) 158 return; 159 m_pTextEdit->setScrollBarMarkingsVector(vector); 321 160 repaint(); 322 161 } … … 324 163 void UIVMLogPage::clearScrollBarMarkingsVector() 325 164 { 326 if (!m_pPlainTextEdit) 327 return; 328 UIIndicatorScrollBar* scrollBar = qobject_cast<UIIndicatorScrollBar*>(m_pPlainTextEdit->verticalScrollBar()); 329 if (scrollBar) 330 scrollBar->clearMarkingsVector(); 165 if (!m_pTextEdit) 166 return; 167 m_pTextEdit->clearScrollBarMarkingsVector(); 331 168 repaint(); 332 169 } … … 334 171 void UIVMLogPage::documentUndo() 335 172 { 336 if (!m_p PlainTextEdit)337 return; 338 if (m_p PlainTextEdit->document())339 m_p PlainTextEdit->document()->undo();173 if (!m_pTextEdit) 174 return; 175 if (m_pTextEdit->document()) 176 m_pTextEdit->document()->undo(); 340 177 } 341 178 … … 355 192 void UIVMLogPage::scrollToBookmark(int bookmarkIndex) 356 193 { 357 if(!m_p PlainTextEdit)194 if(!m_pTextEdit) 358 195 return; 359 196 if (bookmarkIndex >= m_bookmarkVector.size()) … … 361 198 362 199 int lineNumber = m_bookmarkVector.at(bookmarkIndex).first; 363 QTextDocument* document = m_p PlainTextEdit->document();200 QTextDocument* document = m_pTextEdit->document(); 364 201 if(!document) 365 202 return; 366 203 367 204 QTextCursor cursor(document->findBlockByLineNumber(lineNumber)); 368 m_pPlainTextEdit->setTextCursor(cursor); 205 m_pTextEdit->moveCursor(QTextCursor::End); 206 m_pTextEdit->setTextCursor(cursor); 207 369 208 } 370 209 … … 393 232 // sltCreateBookmarkAtLine(bookmark); 394 233 //} 395 396 397 #include "UIVMLogPage.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h
r70549 r70554 28 28 #include "QIWithRetranslateUI.h" 29 29 30 /* COM includes: */31 #include "COMEnums.h"32 #include "CMachine.h"33 34 30 /* Forward declarations: */ 35 31 class QITabWidget; 32 class QHBoxLayout; 36 33 class QPlainTextEdit; 37 class QHBoxLayout; 38 class UIToolBar; 39 class UIVMLogViewerBookmarksPanel; 40 class UIVMLogViewerFilterPanel; 41 class UIVMLogViewerPanel; 42 class UIVMLogViewerSearchPanel; 34 class UIVMLogViewerTextEdit; 43 35 44 36 /* Type definitions: */ … … 109 101 110 102 QHBoxLayout *m_pMainLayout; 111 QPlainTextEdit *m_pPlainTextEdit;103 UIVMLogViewerTextEdit *m_pTextEdit; 112 104 /** Stores the log file (unmodified) content. */ 113 105 QString m_strLog; -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp
r70549 r70554 21 21 22 22 /* Qt includes: */ 23 # include <QDateTime>24 # include <QDir>25 # include <QVBoxLayout>26 23 # if defined(RT_OS_SOLARIS) 27 24 # include <QFontDatabase> 28 25 # endif 26 # include <QMenu> 29 27 # include <QPainter> 30 28 # include <QPlainTextEdit> … … 33 31 34 32 /* GUI includes: */ 35 # include "QIFileDialog.h" 36 # include "QITabWidget.h" 37 # include "UIExtraDataManager.h" 38 # include "UIIconPool.h" 39 # include "UIMessageCenter.h" 40 # include "UIVMLogPage.h" 41 # include "UIVMLogViewerBookmarksPanel.h" 42 # include "UIVMLogViewerFilterPanel.h" 43 # include "UIVMLogViewerSearchPanel.h" 44 # include "UIToolBar.h" 45 46 /* COM includes: */ 47 # include "CSystemProperties.h" 48 49 # include "VBoxGlobal.h" 33 # include "UIVMLogViewerTextEdit.h" 50 34 51 35 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 52 53 36 54 37 /** We use a modified scrollbar style for our QPlainTextEdits to get the … … 125 108 }; 126 109 127 /* Sub-class QPlainTextEdit for some addtional context menu items: */ 128 class UIVMLogViewerTextEdit : public QPlainTextEdit 129 { 130 Q_OBJECT; 131 132 signals: 133 134 void sigContextMenuBookmarkAction(LogBookmark bookmark); 135 110 class UILineNumberArea : public QWidget 111 { 136 112 public: 137 UIVMLogViewerTextEdit(QWidget* parent = 0) 138 :QPlainTextEdit(parent) 139 { 140 //setStyleSheet("background-color: rgba(240, 240, 240, 75%) "); 113 UILineNumberArea(UIVMLogViewerTextEdit *textEdit) 114 :QWidget(textEdit) 115 , m_pTextEdit(textEdit){} 116 117 QSize sizeHint() const override 118 { 119 return QSize(m_pTextEdit->lineNumberAreaWidth(), 0); 141 120 } 142 121 143 122 protected: 144 123 145 void contextMenuEvent(QContextMenuEvent *pEvent) 146 { 147 QMenu *menu = createStandardContextMenu(); 148 QAction *pAction = menu->addAction(tr("Bookmark")); 149 QTextBlock block = cursorForPosition(pEvent->pos()).block(); 150 m_iContextMenuBookmark.first = block.firstLineNumber(); 151 m_iContextMenuBookmark.second = block.text(); 152 153 if (pAction) 154 connect(pAction, &QAction::triggered, this, &UIVMLogViewerTextEdit::sltBookmark); 155 156 menu->exec(pEvent->globalPos()); 157 158 if (pAction) 159 disconnect(pAction, &QAction::triggered, this, &UIVMLogViewerTextEdit::sltBookmark); 160 161 delete menu; 162 } 163 164 virtual void mousePressEvent(QMouseEvent *pEvent) 165 { 166 QPlainTextEdit::mousePressEvent(pEvent); 167 } 168 169 private slots: 170 171 void sltBookmark() 172 { 173 emit sigContextMenuBookmarkAction(m_iContextMenuBookmark); 124 void paintEvent(QPaintEvent *event) override 125 { 126 m_pTextEdit->lineNumberAreaPaintEvent(event); 174 127 } 175 128 176 129 private: 177 178 /* Line number and text at the context menu position */ 179 LogBookmark m_iContextMenuBookmark; 130 UIVMLogViewerTextEdit *m_pTextEdit; 180 131 }; 181 132 182 133 183 UIVMLog Page::UIVMLogPage(QWidget *pParent /* = 0 */, int tabIndex /*= -1*/)184 : QIWithRetranslateUI<QWidget>(pParent)185 , m_p MainLayout(0)186 , m_pPlainTextEdit(0) 187 , m_tabIndex(tabIndex) 188 { 134 UIVMLogViewerTextEdit::UIVMLogViewerTextEdit(QWidget* parent /* = 0 */) 135 :QPlainTextEdit(parent) 136 , m_pLineNumberArea(0) 137 { 138 139 //setStyleSheet("background-color: rgba(240, 240, 240, 75%) "); 189 140 prepare(); 190 141 } 191 142 192 UIVMLogPage::~UIVMLogPage() 193 { 194 cleanup(); 195 } 196 197 int UIVMLogPage::defaultLogPageWidth() const 198 { 199 if (!m_pPlainTextEdit) 200 return 0; 201 202 /* Compute a width for 132 characters plus scrollbar and frame width: */ 203 int iDefaultWidth = m_pPlainTextEdit->fontMetrics().width(QChar('x')) * 132 + 204 m_pPlainTextEdit->verticalScrollBar()->width() + 205 m_pPlainTextEdit->frameWidth() * 2; 206 207 return iDefaultWidth; 208 } 209 210 211 void UIVMLogPage::prepare() 143 void UIVMLogViewerTextEdit::prepare() 212 144 { 213 145 prepareWidgets(); 214 retranslateUi(); 215 } 216 217 void UIVMLogPage::prepareWidgets() 218 { 219 m_pMainLayout = new QHBoxLayout(); 220 setLayout(m_pMainLayout); 221 m_pMainLayout->setSpacing(0); 222 m_pMainLayout->setContentsMargins(0, 0, 0, 0); 223 224 m_pPlainTextEdit = new UIVMLogViewerTextEdit(this); 225 m_pMainLayout->addWidget(m_pPlainTextEdit); 226 227 m_pPlainTextEdit->setVerticalScrollBar(new UIIndicatorScrollBar()); 228 m_pPlainTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); 229 QScrollBar *pHorizontalScrollBar = m_pPlainTextEdit->horizontalScrollBar(); 146 } 147 148 void UIVMLogViewerTextEdit::prepareWidgets() 149 { 150 m_pLineNumberArea = new UILineNumberArea(this); 151 152 connect(this, &UIVMLogViewerTextEdit::blockCountChanged, this, &UIVMLogViewerTextEdit::sltUpdateLineNumberAreaWidth); 153 connect(this, &UIVMLogViewerTextEdit::updateRequest, this, &UIVMLogViewerTextEdit::sltUpdateLineNumberArea); 154 sltUpdateLineNumberAreaWidth(0); 155 156 setVerticalScrollBar(new UIIndicatorScrollBar()); 157 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); 158 QScrollBar *pHorizontalScrollBar = horizontalScrollBar(); 230 159 if (pHorizontalScrollBar) 231 160 pHorizontalScrollBar->setStyleSheet(horizontalScrollBarStyle); 161 232 162 233 163 #if defined(RT_OS_SOLARIS) … … 238 168 font.setFamily("Courier New,courier"); 239 169 #endif 240 m_pPlainTextEdit->setFont(font); 241 m_pPlainTextEdit->setWordWrapMode(QTextOption::NoWrap); 242 m_pPlainTextEdit->setReadOnly(true); 243 connect(qobject_cast<UIVMLogViewerTextEdit*>(m_pPlainTextEdit), &UIVMLogViewerTextEdit::sigContextMenuBookmarkAction, 244 this, &UIVMLogPage::sltAddBookmark); 245 } 246 247 QPlainTextEdit *UIVMLogPage::textEdit() 248 { 249 return m_pPlainTextEdit; 250 } 251 252 QTextDocument* UIVMLogPage::document() 253 { 254 if (!m_pPlainTextEdit) 255 return 0; 256 return m_pPlainTextEdit->document(); 257 } 258 259 void UIVMLogPage::setTabIndex(int index) 260 { 261 m_tabIndex = index; 262 } 263 264 int UIVMLogPage::tabIndex() const 265 { 266 return m_tabIndex; 267 } 268 269 void UIVMLogPage::retranslateUi() 270 { 271 } 272 273 void UIVMLogPage::cleanup() 274 { 275 } 276 277 void UIVMLogPage::setLogString(const QString &strLog) 278 { 279 m_strLog = strLog; 280 } 281 282 const QString& UIVMLogPage::logString() const 283 { 284 return m_strLog; 285 } 286 287 void UIVMLogPage::setFileName(const QString &strFileName) 288 { 289 m_strFileName = strFileName; 290 } 291 292 const QString& UIVMLogPage::fileName() const 293 { 294 return m_strFileName; 295 } 296 297 void UIVMLogPage::setTextEdit(const QString &strText) 298 { 299 m_pPlainTextEdit->setPlainText(strText); 300 /* Move the cursor position to end: */ 301 QTextCursor cursor = m_pPlainTextEdit->textCursor(); 302 cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); 303 m_pPlainTextEdit->setTextCursor(cursor); 304 repaint(); 305 } 306 307 void UIVMLogPage::markForError() 308 { 309 QPalette pal = m_pPlainTextEdit->palette(); 310 pal.setColor(QPalette::Base, pal.color(QPalette::Window)); 311 m_pPlainTextEdit->setPalette(pal); 312 } 313 314 void UIVMLogPage::setScrollBarMarkingsVector(const QVector<float> &vector) 315 { 316 if (!m_pPlainTextEdit) 317 return; 318 UIIndicatorScrollBar* scrollBar = qobject_cast<UIIndicatorScrollBar*>(m_pPlainTextEdit->verticalScrollBar()); 319 if (scrollBar) 320 scrollBar->setMarkingsVector(vector); 321 repaint(); 322 } 323 324 void UIVMLogPage::clearScrollBarMarkingsVector() 325 { 326 if (!m_pPlainTextEdit) 327 return; 328 UIIndicatorScrollBar* scrollBar = qobject_cast<UIIndicatorScrollBar*>(m_pPlainTextEdit->verticalScrollBar()); 329 if (scrollBar) 330 scrollBar->clearMarkingsVector(); 331 repaint(); 332 } 333 334 void UIVMLogPage::documentUndo() 335 { 336 if (!m_pPlainTextEdit) 337 return; 338 if (m_pPlainTextEdit->document()) 339 m_pPlainTextEdit->document()->undo(); 340 } 341 342 343 void UIVMLogPage::deleteBookmark(int index) 344 { 345 if (m_bookmarkVector.size() <= index) 346 return; 347 m_bookmarkVector.remove(index, 1); 348 } 349 350 void UIVMLogPage::deleteAllBookmarks() 351 { 352 m_bookmarkVector.clear(); 353 } 354 355 void UIVMLogPage::scrollToBookmark(int bookmarkIndex) 356 { 357 if(!m_pPlainTextEdit) 358 return; 359 if (bookmarkIndex >= m_bookmarkVector.size()) 360 return; 361 362 int lineNumber = m_bookmarkVector.at(bookmarkIndex).first; 363 QTextDocument* document = m_pPlainTextEdit->document(); 364 if(!document) 365 return; 366 367 QTextCursor cursor(document->findBlockByLineNumber(lineNumber)); 368 m_pPlainTextEdit->setTextCursor(cursor); 369 } 370 371 const QVector<LogBookmark>& UIVMLogPage::bookmarkVector() const 372 { 373 return m_bookmarkVector; 374 } 375 376 void UIVMLogPage::sltAddBookmark(LogBookmark bookmark) 377 { 378 m_bookmarkVector.push_back(bookmark); 379 emit sigBookmarksUpdated(); 380 } 381 // void UIVMLogViewerWidget::sltCreateBookmarkAtCurrent() 382 // { 383 // if (!currentTextEdit()) 384 // return; 385 // QWidget* viewport = currentTextEdit()->viewport(); 386 // if (!viewport) 387 // return; 388 // QPoint point(0.5 * viewport->width(), 0.5 * viewport->height()); 389 // QTextBlock block = currentTextEdit()->cursorForPosition(point).block(); 390 // LogBookmark bookmark; 391 // bookmark.first = block.firstLineNumber(); 392 // bookmark.second = block.text(); 393 // sltCreateBookmarkAtLine(bookmark); 394 //} 395 396 397 #include "UIVMLogPage.moc" 170 setFont(font); 171 setWordWrapMode(QTextOption::NoWrap); 172 setReadOnly(true); 173 if(m_pLineNumberArea) 174 m_pLineNumberArea->setFont(font); 175 176 } 177 178 int UIVMLogViewerTextEdit::lineNumberAreaWidth() 179 { 180 int digits = 1; 181 int max = qMax(1, blockCount()); 182 while (max >= 10) { 183 max /= 10; 184 ++digits; 185 } 186 187 int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; 188 189 return space; 190 } 191 192 void UIVMLogViewerTextEdit::lineNumberAreaPaintEvent(QPaintEvent *event) 193 { 194 QPainter painter(m_pLineNumberArea); 195 painter.fillRect(event->rect(), Qt::lightGray); 196 QTextBlock block = firstVisibleBlock(); 197 int blockNumber = block.blockNumber(); 198 int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); 199 int bottom = top + (int) blockBoundingRect(block).height(); 200 while (block.isValid() && top <= event->rect().bottom()) { 201 if (block.isVisible() && bottom >= event->rect().top()) { 202 QString number = QString::number(blockNumber + 1); 203 painter.setPen(Qt::black); 204 painter.drawText(0, top, m_pLineNumberArea->width(), m_pLineNumberArea->fontMetrics().lineSpacing(), 205 Qt::AlignRight, number); 206 } 207 block = block.next(); 208 top = bottom; 209 bottom = top + (int) blockBoundingRect(block).height(); 210 ++blockNumber; 211 } 212 } 213 214 void UIVMLogViewerTextEdit::contextMenuEvent(QContextMenuEvent *pEvent) 215 { 216 QMenu *menu = createStandardContextMenu(); 217 QAction *pAction = menu->addAction(tr("Bookmark")); 218 QTextBlock block = cursorForPosition(pEvent->pos()).block(); 219 m_iContextMenuBookmark.first = block.firstLineNumber(); 220 m_iContextMenuBookmark.second = block.text(); 221 222 if (pAction) 223 connect(pAction, &QAction::triggered, this, &UIVMLogViewerTextEdit::sltBookmark); 224 225 menu->exec(pEvent->globalPos()); 226 227 if (pAction) 228 disconnect(pAction, &QAction::triggered, this, &UIVMLogViewerTextEdit::sltBookmark); 229 230 delete menu; 231 } 232 233 void UIVMLogViewerTextEdit::resizeEvent(QResizeEvent *pEvent) 234 { 235 QPlainTextEdit::resizeEvent(pEvent); 236 237 QRect cr = contentsRect(); 238 m_pLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); 239 } 240 241 242 void UIVMLogViewerTextEdit::sltUpdateLineNumberAreaWidth(int /* newBlockCount */) 243 { 244 setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); 245 } 246 247 void UIVMLogViewerTextEdit::sltUpdateLineNumberArea(const QRect &rect, int dy) 248 { 249 if (dy) 250 m_pLineNumberArea->scroll(0, dy); 251 else 252 m_pLineNumberArea->update(0, rect.y(), m_pLineNumberArea->width(), rect.height()); 253 254 if (rect.contains(viewport()->rect())) 255 sltUpdateLineNumberAreaWidth(0); 256 } 257 258 void UIVMLogViewerTextEdit::sltBookmark() 259 { 260 emit sigContextMenuBookmarkAction(m_iContextMenuBookmark); 261 } 262 263 void UIVMLogViewerTextEdit::setScrollBarMarkingsVector(const QVector<float> &vector) 264 { 265 UIIndicatorScrollBar* vScrollBar = qobject_cast<UIIndicatorScrollBar*>(verticalScrollBar()); 266 if(vScrollBar) 267 vScrollBar->setMarkingsVector(vector); 268 } 269 270 void UIVMLogViewerTextEdit::clearScrollBarMarkingsVector() 271 { 272 UIIndicatorScrollBar* vScrollBar = qobject_cast<UIIndicatorScrollBar*>(verticalScrollBar()); 273 if(vScrollBar) 274 vScrollBar->clearMarkingsVector(); 275 } 276 277 278 #include "UIVMLogViewerTextEdit.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h
r70549 r70554 16 16 */ 17 17 18 #ifndef ___UIVMLog Page_h___19 #define ___UIVMLog Page_h___18 #ifndef ___UIVMLogViewerTextEdit_h___ 19 #define ___UIVMLogViewerTextEdit_h___ 20 20 21 21 /* Qt includes: */ 22 #include <QWidget> 23 /* #include <QMap> */ 22 #include <QPlainTextEdit> 24 23 #include <QPair> 25 24 26 /* GUI includes: */27 #include "QIManagerDialog.h"28 #include "QIWithRetranslateUI.h"29 25 30 /* COM includes: */ 31 #include "COMEnums.h" 32 #include "CMachine.h" 33 34 /* Forward declarations: */ 35 class QITabWidget; 36 class QPlainTextEdit; 37 class QHBoxLayout; 38 class UIToolBar; 39 class UIVMLogViewerBookmarksPanel; 40 class UIVMLogViewerFilterPanel; 41 class UIVMLogViewerPanel; 42 class UIVMLogViewerSearchPanel; 43 44 /* Type definitions: */ 45 /** first is line number, second is block text */ 46 typedef QPair<int, QString> LogBookmark; 47 48 class UIVMLogPage : public QIWithRetranslateUI<QWidget> 26 /* QPlainTextEdit extension for some addtional context menu items, 27 a special scrollbar, line number area, and bookmark support: */ 28 class UIVMLogViewerTextEdit : public QPlainTextEdit 49 29 { 50 30 Q_OBJECT; … … 52 32 signals: 53 33 54 void sig BookmarksUpdated();34 void sigContextMenuBookmarkAction(QPair<int, QString> bookmark); 55 35 56 36 public: 57 37 58 UIVMLogPage(QWidget *pParent = 0, int tabIndex = -1); 59 /** Destructs the VM Log-Viewer. */ 60 ~UIVMLogPage(); 61 /** Returns the width of the current log page. return 0 if there is no current log page: */ 62 int defaultLogPageWidth() const; 63 64 QPlainTextEdit *textEdit(); 65 QTextDocument *document(); 66 67 void setTabIndex(int index); 68 int tabIndex() const; 69 70 /* Only to be called when log file is re-read. */ 71 void setLogString(const QString &strLog); 72 const QString& logString() const; 73 74 void setFileName(const QString &strFileName); 75 const QString& fileName() const; 76 77 /** Ses plaintextEdit's text. Note that the text we 78 show currently might be different than 79 m_strLog. For example during filtering. */ 80 void setTextEdit(const QString &strText); 81 82 /** Marks the plain text edit When we dont have a log content. */ 83 void markForError(); 84 38 UIVMLogViewerTextEdit(QWidget* parent = 0); 39 int lineNumberAreaWidth(); 40 void lineNumberAreaPaintEvent(QPaintEvent *event); 41 /** Forwards the call to scroll bar class */ 85 42 void setScrollBarMarkingsVector(const QVector<float> &vector); 43 /** Forwards the call to scroll bar class */ 86 44 void clearScrollBarMarkingsVector(); 87 88 /** Undos the changes done to textDocument */89 void documentUndo();90 91 void deleteBookmark(int index);92 93 const QVector<LogBookmark>& bookmarkVector() const;94 void deleteAllBookmarks();95 /** Scrolls the plain text edit to the bookmark with index @a bookmarkIndex. */96 void scrollToBookmark(int bookmarkIndex);97 45 98 46 protected: 99 47 48 void contextMenuEvent(QContextMenuEvent *pEvent); 49 void resizeEvent(QResizeEvent *pEvent); 50 100 51 private slots: 101 52 102 void sltAddBookmark(LogBookmark bookmark); 53 void sltBookmark(); 54 void sltUpdateLineNumberAreaWidth(int newBlockCount); 55 void sltUpdateLineNumberArea(const QRect &, int); 103 56 104 57 private: 58 105 59 void prepare(); 106 60 void prepareWidgets(); 107 void cleanup();108 void retranslateUi();109 61 110 QHBoxLayout *m_pMainLayout; 111 QPlainTextEdit *m_pPlainTextEdit; 112 /** Stores the log file (unmodified) content. */ 113 QString m_strLog; 114 /** Stores full path and name of the log file. */ 115 QString m_strFileName; 116 /** This is the index of the tab containing this widget in UIVMLogViewerWidget. */ 117 int m_tabIndex; 118 119 QVector<LogBookmark> m_bookmarkVector; 120 62 /* Line number and text at the context menu position */ 63 QPair<int, QString> m_iContextMenuBookmark; 64 QWidget *m_pLineNumberArea; 121 65 }; 122 66 67 68 69 123 70 #endif /* !___UIVMLogPage_h___ */
Note:
See TracChangeset
for help on using the changeset viewer.