Fix some warnings

pull/2/head
reionwong 4 years ago
parent 3fbb98876c
commit a8f62f6a64

@ -33,6 +33,7 @@ set(SRCS
src/main.cpp src/main.cpp
src/processhelper.h src/processhelper.h
src/processhelper.cpp src/processhelper.cpp
src/utils.cpp
) )
set(RESOURCES set(RESOURCES

@ -2674,7 +2674,12 @@ void TerminalDisplay::bracketText(QString& text)
void TerminalDisplay::setSelection(const QString& t) void TerminalDisplay::setSelection(const QString& t)
{ {
QApplication::clipboard()->setText(t, QClipboard::Selection); QApplication::clipboard()->setText(t, QClipboard::Selection);
}
bool TerminalDisplay::selectedText()
{
return !_screenWindow->selectedText(false).isEmpty();
} }
void TerminalDisplay::copyClipboard() void TerminalDisplay::copyClipboard()

@ -103,6 +103,8 @@ class KONSOLEPRIVATE_EXPORT TerminalDisplay : public QQuickPaintedItem
Q_PROPERTY(bool antialiasText READ antialias WRITE setAntialias) Q_PROPERTY(bool antialiasText READ antialias WRITE setAntialias)
Q_PROPERTY(QStringList availableColorSchemes READ availableColorSchemes NOTIFY availableColorSchemesChanged) Q_PROPERTY(QStringList availableColorSchemes READ availableColorSchemes NOTIFY availableColorSchemesChanged)
Q_PROPERTY(bool selectedText READ selectedText CONSTANT)
public: public:
/** Constructs a new terminal display widget with the specified parent. */ /** Constructs a new terminal display widget with the specified parent. */
TerminalDisplay(QQuickItem *parent=0); TerminalDisplay(QQuickItem *parent=0);
@ -362,6 +364,7 @@ public:
}; };
void setSelection(const QString &t); void setSelection(const QString &t);
bool selectedText();
/** /**
* Reimplemented. Has no effect. Use setVTFont() to change the font * Reimplemented. Has no effect. Use setVTFont() to change the font

@ -25,6 +25,7 @@
#include <QFile> #include <QFile>
#include "processhelper.h" #include "processhelper.h"
#include "utils.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -47,6 +48,8 @@ int main(int argc, char *argv[])
} }
engine.rootContext()->setContextProperty("Process", new ProcessHelper); engine.rootContext()->setContextProperty("Process", new ProcessHelper);
engine.rootContext()->setContextProperty("Utils", new Utils);
engine.addImportPath(QStringLiteral("qrc:/")); engine.addImportPath(QStringLiteral("qrc:/"));
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));

@ -122,6 +122,7 @@ Page {
onPressed: { onPressed: {
if ((!_terminal.terminalUsesMouse || mouse.modifiers & Qt.ShiftModifier) if ((!_terminal.terminalUsesMouse || mouse.modifiers & Qt.ShiftModifier)
&& mouse.button == Qt.RightButton) { && mouse.button == Qt.RightButton) {
updateMenu()
terminalMenu.open() terminalMenu.open()
} else { } else {
var coord = correctDistortion(mouse.x, mouse.y) var coord = correctDistortion(mouse.x, mouse.y)
@ -141,8 +142,8 @@ Page {
onClicked: { onClicked: {
if (mouse.button === Qt.RightButton) { if (mouse.button === Qt.RightButton) {
updateMenu()
terminalMenu.open() terminalMenu.open()
} else if(mouse.button === Qt.LeftButton) { } else if(mouse.button === Qt.LeftButton) {
_terminal.forceActiveFocus() _terminal.forceActiveFocus()
} }
@ -216,4 +217,9 @@ Page {
return Qt.point((x - cc.width * (1 + distortion) * distortion) * _terminal.width, return Qt.point((x - cc.width * (1 + distortion) * distortion) * _terminal.width,
(y - cc.height * (1 + distortion) * distortion) * _terminal.height) (y - cc.height * (1 + distortion) * distortion) * _terminal.height)
} }
function updateMenu() {
pasteAction.visible = Utils.text()
copyAction.visible = _terminal.selectedText
}
} }

@ -38,7 +38,7 @@ FishUI.Window {
property int currentIndex: -1 property int currentIndex: -1
property alias currentItem: _view.currentItem property alias currentItem: _view.currentItem
readonly property QMLTermWidget currentTerminal: currentItem.terminal readonly property QMLTermWidget currentTerminal: currentItem ? currentItem.terminal : null
GlobalSettings { id: settings } GlobalSettings { id: settings }
ObjectModel { id: tabsModel } ObjectModel { id: tabsModel }
@ -71,7 +71,7 @@ FishUI.Window {
anchors.leftMargin: FishUI.Units.smallSpacing anchors.leftMargin: FishUI.Units.smallSpacing
anchors.rightMargin: FishUI.Units.smallSpacing anchors.rightMargin: FishUI.Units.smallSpacing
anchors.topMargin: FishUI.Units.smallSpacing anchors.topMargin: FishUI.Units.smallSpacing
anchors.bottomMargin: FishUI.Units.smallSpacing anchors.bottomMargin: FishUI.Units.smallSpacing / 2
spacing: FishUI.Units.smallSpacing spacing: FishUI.Units.smallSpacing
ListView { ListView {
@ -90,7 +90,7 @@ FishUI.Window {
delegate: Item { delegate: Item {
id: _tabItem id: _tabItem
height: root.header.height - FishUI.Units.largeSpacing height: root.header.height - FishUI.Units.largeSpacing + FishUI.Units.smallSpacing / 2
width: Math.min(_layout.implicitWidth + FishUI.Units.largeSpacing, width: Math.min(_layout.implicitWidth + FishUI.Units.largeSpacing,
_tabView.width / _tabView.count - FishUI.Units.smallSpacing) _tabView.width / _tabView.count - FishUI.Units.smallSpacing)
@ -106,7 +106,8 @@ FishUI.Window {
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
color: isCurrent ? FishUI.Theme.secondBackgroundColor : "transparent" color: isCurrent ? FishUI.Theme.highlightColor : "transparent"
opacity: 0.1
border.width: 0 border.width: 0
radius: FishUI.Theme.smallRadius radius: FishUI.Theme.smallRadius
} }
@ -152,6 +153,7 @@ FishUI.Window {
} }
} }
ListView { ListView {
id: _view id: _view
anchors.fill: parent anchors.fill: parent
@ -202,7 +204,6 @@ FishUI.Window {
_view.currentIndex = index _view.currentIndex = index
object.terminalClosed.connect(() => closeTab(index)) object.terminalClosed.connect(() => closeTab(index))
} }
} }
function closeTab(index) { function closeTab(index) {

@ -0,0 +1,43 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Reion Wong <reionwong@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "utils.h"
#include <QApplication>
#include <QClipboard>
static Utils *SELF = nullptr;
Utils *Utils::self()
{
if (!SELF)
SELF = new Utils;
return SELF;
}
Utils::Utils(QObject *parent)
: QObject(parent)
{
}
QString Utils::text() const
{
return qApp->clipboard()->text();
}

@ -0,0 +1,36 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Reion Wong <reionwong@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UTILS_H
#define UTILS_H
#include <QObject>
class Utils : public QObject
{
Q_OBJECT
public:
static Utils *self();
explicit Utils(QObject *parent = nullptr);
Q_INVOKABLE QString text() const;
};
#endif // UTILS_H
Loading…
Cancel
Save