- Timestamp:
- Jan 26, 2023 12:52:40 PM (2 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/extensions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIRichTextLabel.cpp
r98103 r98312 28 28 /* Qt includes: */ 29 29 #include <QAccessibleWidget> 30 #include <QAction> 31 #include <QApplication> 32 #include <QClipboard> 30 33 #include <QtMath> 31 34 #include <QUrl> … … 101 104 102 105 QIRichTextLabel::QIRichTextLabel(QWidget *pParent) 103 : Q Widget(pParent)106 : QIWithRetranslateUI<QWidget>(pParent) 104 107 , m_pTextBrowser() 108 , m_pActionCopy(0) 109 , m_fCopyAvailable(false) 105 110 , m_iMinimumTextWidth(0) 106 111 { … … 124 129 /* Configure text-browser: */ 125 130 m_pTextBrowser->setReadOnly(true); 126 m_pTextBrowser->setFocusPolicy(Qt:: NoFocus);131 m_pTextBrowser->setFocusPolicy(Qt::ClickFocus); 127 132 m_pTextBrowser->setFrameShape(QFrame::NoFrame); 128 133 m_pTextBrowser->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 129 134 m_pTextBrowser->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 135 m_pTextBrowser->setContextMenuPolicy(Qt::ActionsContextMenu); 130 136 m_pTextBrowser->setOpenExternalLinks(true); 131 137 … … 140 146 /* Setup connections finally: */ 141 147 connect(m_pTextBrowser, &QTextBrowser::anchorClicked, this, &QIRichTextLabel::sigLinkClicked); 148 connect(m_pTextBrowser, &QTextBrowser::copyAvailable, this, &QIRichTextLabel::sltHandleCopyAvailable); 149 150 /* Create context-menu copy action for text-browser: */ 151 m_pActionCopy = new QAction(m_pTextBrowser); 152 if (m_pActionCopy) 153 { 154 m_pActionCopy->setShortcut(QKeySequence(QKeySequence::Copy)); 155 m_pActionCopy->setShortcutContext(Qt::WidgetShortcut); 156 connect(m_pActionCopy, &QAction::triggered, this, &QIRichTextLabel::copy); 157 m_pTextBrowser->addAction(m_pActionCopy); 158 } 142 159 } 143 160 … … 145 162 pMainLayout->addWidget(m_pTextBrowser); 146 163 } 164 165 /* Apply language settings: */ 166 retranslateUi(); 147 167 } 148 168 … … 246 266 setMinimumTextWidth(m_iMinimumTextWidth == 0 ? newSize.width() : m_iMinimumTextWidth); 247 267 } 268 269 void QIRichTextLabel::copy() 270 { 271 // WORKAROUND: 272 // We should distinguish whether copy() is available or not. 273 // If it is, we can use QTextBrowser::copy() directly to 274 // copy selected part of text. Otherwise we have to use 275 // QTextBrowser::toPlainText() to get the whole desirable 276 // text and put it to QClipboard ourselves. 277 if (m_fCopyAvailable) 278 m_pTextBrowser->copy(); 279 else 280 { 281 /* Copy the current text to the global and selection clipboards: */ 282 const QString strText = m_pTextBrowser->toPlainText(); 283 QApplication::clipboard()->setText(strText, QClipboard::Clipboard); 284 QApplication::clipboard()->setText(strText, QClipboard::Selection); 285 } 286 } 287 288 void QIRichTextLabel::retranslateUi() 289 { 290 if (m_pActionCopy) 291 m_pActionCopy->setText(tr("&Copy")); 292 } -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIRichTextLabel.h
r98103 r98312 36 36 37 37 /* GUI includes: */ 38 #include "QIWithRetranslateUI.h" 38 39 #include "UILibraryDefs.h" 40 41 /* Forward declarations: */ 42 class QAction; 39 43 40 44 /** QLabel analog to reflect rich-text, 41 45 ** based on private QTextBrowser functionality. */ 42 class SHARED_LIBRARY_STUFF QIRichTextLabel : public Q Widget46 class SHARED_LIBRARY_STUFF QIRichTextLabel : public QIWithRetranslateUI<QWidget> 43 47 { 44 48 Q_OBJECT; … … 88 92 void setText(const QString &strText); 89 93 94 /** Copies text-browser text into clipboard. */ 95 void copy(); 96 97 protected: 98 99 /** Handles translation event. */ 100 virtual void retranslateUi() RT_OVERRIDE; 101 102 private slots: 103 104 /** Handles the fact of text-browser text copy available. 105 * @param fYes Brings whether some text is selected and can 106 * be copied directly by QTextBrowser::copy() call. */ 107 void sltHandleCopyAvailable(bool fYes) { m_fCopyAvailable = fYes; } 108 90 109 private: 91 110 92 111 /** Holds the text-browser instance. */ 93 112 QTextBrowser *m_pTextBrowser; 113 114 /** Holds the context-menu Copy action instance. */ 115 QAction *m_pActionCopy; 116 /** Holds whether text-browser text copy is available. */ 117 bool m_fCopyAvailable; 94 118 95 119 /** Holds the minimum text-width. */
Note:
See TracChangeset
for help on using the changeset viewer.