Commit caf0ab2b authored by Kurt Hindenburg's avatar Kurt Hindenburg

Add a profile property to toggle copying text as HTML

The default behavior hasn't change.  Toggling this off will cause all
copy/paste to be text only.

BUG: 387397
FIXED-IN: 18.04
Differential Revision: https://phabricator.kde.org/D10448
parent e81b0112
......@@ -1269,6 +1269,10 @@ void EditProfileDialog::setupMousePage(const Profile::Ptr profile)
_ui->ctrlRequiredForDragButton, Profile::CtrlRequiredForDrag,
SLOT(toggleCtrlRequiredForDrag(bool))
},
{
_ui->copyTextAsHTMLButton, Profile::CopyTextAsHTML,
SLOT(toggleCopyTextAsHTML(bool))
},
{
_ui->copyTextToClipboardButton, Profile::AutoCopySelectedText,
SLOT(toggleCopyTextToClipboard(bool))
......@@ -1467,6 +1471,11 @@ void EditProfileDialog::toggleOpenLinksByDirectClick(bool enable)
updateTempProfileProperty(Profile::OpenLinksByDirectClickEnabled, enable);
}
void EditProfileDialog::toggleCopyTextAsHTML(bool enable)
{
updateTempProfileProperty(Profile::CopyTextAsHTML, enable);
}
void EditProfileDialog::toggleCopyTextToClipboard(bool enable)
{
updateTempProfileProperty(Profile::AutoCopySelectedText, enable);
......
......@@ -170,6 +170,7 @@ private Q_SLOTS:
void toggleCtrlRequiredForDrag(bool);
void toggleDropUrlsAsText(bool);
void toggleCopyTextToClipboard(bool);
void toggleCopyTextAsHTML(bool);
void toggleTrimLeadingSpacesInSelectedText(bool);
void toggleTrimTrailingSpacesInSelectedText(bool);
void pasteFromX11Selection();
......
......@@ -952,18 +952,8 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="copyTextToClipboardButton">
<property name="toolTip">
<string>Automatically copy selected text into clipboard</string>
</property>
<property name="text">
<string>Copy on select</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="trimLeadingSpacesButton">
<property name="toolTip">
......@@ -986,7 +976,7 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_13">
......@@ -1011,6 +1001,30 @@
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QCheckBox" name="copyTextToClipboardButton">
<property name="toolTip">
<string>Automatically copy selected text into clipboard</string>
</property>
<property name="text">
<string>Copy on select</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="copyTextAsHTMLButton">
<property name="toolTip">
<string>Copy text as HTML (including formatting, font faces, colors... etc)</string>
</property>
<property name="text">
<string>Copy text as HTML</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
......@@ -1109,19 +1123,6 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>328</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="advancedTab">
......
......@@ -114,6 +114,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
, { CtrlRequiredForDrag, "CtrlRequiredForDrag" , INTERACTION_GROUP , QVariant::Bool }
, { DropUrlsAsText , "DropUrlsAsText" , INTERACTION_GROUP , QVariant::Bool }
, { AutoCopySelectedText , "AutoCopySelectedText" , INTERACTION_GROUP , QVariant::Bool }
, { CopyTextAsHTML , "CopyTextAsHTML" , INTERACTION_GROUP , QVariant::Bool }
, { TrimLeadingSpacesInSelectedText , "TrimLeadingSpacesInSelectedText" , INTERACTION_GROUP , QVariant::Bool }
, { TrimTrailingSpacesInSelectedText , "TrimTrailingSpacesInSelectedText" , INTERACTION_GROUP , QVariant::Bool }
, { PasteFromSelectionEnabled , "PasteFromSelectionEnabled" , INTERACTION_GROUP , QVariant::Bool }
......@@ -189,6 +190,7 @@ void Profile::useFallback()
setProperty(OpenLinksByDirectClickEnabled, false);
setProperty(CtrlRequiredForDrag, true);
setProperty(AutoCopySelectedText, false);
setProperty(CopyTextAsHTML, true);
setProperty(TrimLeadingSpacesInSelectedText, false);
setProperty(TrimTrailingSpacesInSelectedText, false);
setProperty(DropUrlsAsText, false);
......
......@@ -205,6 +205,14 @@ public:
CtrlRequiredForDrag,
/** (bool) If true, automatically copy selected text into the clipboard */
AutoCopySelectedText,
/** (bool) The QMimeData object used when copying text always
* has the plain/text MIME set and if this is @c true then the
* text/html MIME is set too in that object i.e. the copied
* text will include formatting, font faces, colors... etc; users
* can paste the text as HTML (default) or as plain/text by using
* e.g. the "Paste Special" functionality in LibreOffice.
*/
CopyTextAsHTML,
/** (bool) If true, leading spaces are trimmed in selected text */
TrimLeadingSpacesInSelectedText,
/** (bool) If true, trailing spaces are trimmed in selected text */
......
......@@ -354,6 +354,7 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _preserveLineBreaks(false)
, _columnSelectionMode(false)
, _autoCopySelectedText(false)
, _copyTextAsHTML(true)
, _middleClickPasteMode(Enum::PasteFromX11Selection)
, _scrollbarLocation(Enum::ScrollBarRight)
, _scrollFullPage(false)
......@@ -3108,6 +3109,11 @@ void TerminalDisplay::setMiddleClickPasteMode(Enum::MiddleClickPasteModeEnum mod
_middleClickPasteMode = mode;
}
void TerminalDisplay::setCopyTextAsHTML(bool enabled)
{
_copyTextAsHTML = enabled;
}
void TerminalDisplay::copyToX11Selection()
{
if (_screenWindow == nullptr) {
......@@ -3115,15 +3121,17 @@ void TerminalDisplay::copyToX11Selection()
}
QString text = _screenWindow->selectedText(currentDecodingOptions());
const QString &text = _screenWindow->selectedText(currentDecodingOptions());
if (text.isEmpty()) {
return;
}
QString html = _screenWindow->selectedText(currentDecodingOptions() | Screen::ConvertToHtml);
auto mimeData = new QMimeData;
mimeData->setText(text);
mimeData->setHtml(html);
if (_copyTextAsHTML) {
mimeData->setHtml(_screenWindow->selectedText(currentDecodingOptions() | Screen::ConvertToHtml));
}
if (QApplication::clipboard()->supportsSelection()) {
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Selection);
......@@ -3140,15 +3148,17 @@ void TerminalDisplay::copyToClipboard()
return;
}
QString text = _screenWindow->selectedText(currentDecodingOptions());
const QString &text = _screenWindow->selectedText(currentDecodingOptions());
if (text.isEmpty()) {
return;
}
QString html = _screenWindow->selectedText(currentDecodingOptions() | Screen::ConvertToHtml);
auto mimeData = new QMimeData;
mimeData->setText(text);
mimeData->setHtml(html);
if (_copyTextAsHTML) {
mimeData->setHtml(_screenWindow->selectedText(currentDecodingOptions() | Screen::ConvertToHtml));
}
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
}
......
......@@ -569,6 +569,8 @@ public Q_SLOTS:
void setAutoCopySelectedText(bool enabled);
void setCopyTextAsHTML(bool enabled);
void setMiddleClickPasteMode(Enum::MiddleClickPasteModeEnum mode);
/** Copies the selected text to the X11 Selection. */
......@@ -915,6 +917,7 @@ private:
bool _columnSelectionMode;
bool _autoCopySelectedText;
bool _copyTextAsHTML;
Enum::MiddleClickPasteModeEnum _middleClickPasteMode;
QScrollBar *_scrollBar;
......
......@@ -930,6 +930,8 @@ void ViewManager::applyProfileToView(TerminalDisplay *view, const Profile::Ptr p
view->setMiddleClickPasteMode(Enum::PasteFromClipboard);
}
view->setCopyTextAsHTML(profile->property<bool>(Profile::CopyTextAsHTML));
// margin/center
view->setMargin(profile->property<int>(Profile::TerminalMargin));
view->setCenterContents(profile->property<bool>(Profile::TerminalCenter));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment