mirror of https://github.com/qTox/qTox.git
14 changed files with 16 additions and 555 deletions
@ -1,27 +0,0 @@
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre 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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#include "clickablelabel.h" |
||||
|
||||
ClickableLabel::ClickableLabel(QWidget *parent) : |
||||
QLabel(parent) |
||||
{ |
||||
} |
||||
|
||||
void ClickableLabel::mousePressEvent(QMouseEvent*) |
||||
{ |
||||
emit clicked(); |
||||
} |
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre 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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#ifndef CLICKABLELABEL_H |
||||
#define CLICKABLELABEL_H |
||||
|
||||
#include <QLabel> |
||||
|
||||
class ClickableLabel : public QLabel |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
explicit ClickableLabel(QWidget *parent = 0); |
||||
|
||||
signals: |
||||
void clicked(); |
||||
|
||||
protected: |
||||
void mousePressEvent ( QMouseEvent * event ); |
||||
|
||||
}; |
||||
|
||||
#endif // CLICKABLELABEL_H
|
@ -1,47 +0,0 @@
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com> |
||||
|
||||
This file is part of Tox Qt GUI. |
||||
|
||||
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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#include "copyableelidelabel.h" |
||||
|
||||
#include <QApplication> |
||||
#include <QMenu> |
||||
#include <QClipboard> |
||||
|
||||
CopyableElideLabel::CopyableElideLabel(QWidget* parent) : |
||||
ElideLabel(parent) |
||||
{ |
||||
setContextMenuPolicy(Qt::CustomContextMenu); |
||||
connect(this, &CopyableElideLabel::customContextMenuRequested, this, &CopyableElideLabel::showContextMenu); |
||||
|
||||
actionCopy = new QAction(CopyableElideLabel::tr("Copy"), this); |
||||
connect(actionCopy, &QAction::triggered, [this]() { |
||||
QApplication::clipboard()->setText(text()); |
||||
}); |
||||
} |
||||
|
||||
void CopyableElideLabel::showContextMenu(const QPoint& pos) |
||||
{ |
||||
if (text().length() == 0) { |
||||
return; |
||||
} |
||||
|
||||
QPoint globalPos = mapToGlobal(pos); |
||||
|
||||
QMenu contextMenu; |
||||
contextMenu.addAction(actionCopy); |
||||
|
||||
contextMenu.exec(globalPos); |
||||
} |
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com> |
||||
|
||||
This file is part of Tox Qt GUI. |
||||
|
||||
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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#ifndef COPYABLEELIDELABEL_HPP |
||||
#define COPYABLEELIDELABEL_HPP |
||||
|
||||
#include "elidelabel.h" |
||||
|
||||
class CopyableElideLabel : public ElideLabel |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
explicit CopyableElideLabel(QWidget* parent = 0); |
||||
|
||||
private: |
||||
QAction* actionCopy; |
||||
|
||||
private slots: |
||||
void showContextMenu(const QPoint& pos); |
||||
|
||||
}; |
||||
|
||||
#endif // COPYABLEELIDELABEL_HPP
|
@ -1,117 +0,0 @@
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com> |
||||
|
||||
This file is part of Tox Qt GUI. |
||||
|
||||
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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#include "editablelabelwidget.h" |
||||
|
||||
#include <QApplication> |
||||
#include <QEvent> |
||||
#include <QFontMetrics> |
||||
#include <QMouseEvent> |
||||
#include <QVBoxLayout> |
||||
|
||||
ClickableCopyableElideLabel::ClickableCopyableElideLabel(QWidget* parent) : |
||||
CopyableElideLabel(parent) |
||||
{ |
||||
} |
||||
|
||||
bool ClickableCopyableElideLabel::event(QEvent* event) |
||||
{ |
||||
if (event->type() == QEvent::MouseButtonRelease) { |
||||
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); |
||||
if (mouseEvent->button() == Qt::LeftButton) { |
||||
emit clicked(); |
||||
} |
||||
} else if (event->type() == QEvent::Enter) { |
||||
QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor)); |
||||
} else if (event->type() == QEvent::Leave) { |
||||
QApplication::restoreOverrideCursor(); |
||||
} |
||||
|
||||
return CopyableElideLabel::event(event); |
||||
} |
||||
|
||||
EditableLabelWidget::EditableLabelWidget(QWidget* parent) : |
||||
QStackedWidget(parent), isSubmitting(false) |
||||
{ |
||||
label = new ClickableCopyableElideLabel(this); |
||||
|
||||
connect(label, &ClickableCopyableElideLabel::clicked, this, &EditableLabelWidget::onLabelClicked); |
||||
|
||||
lineEdit = new EscLineEdit(this); |
||||
lineEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); |
||||
lineEdit->setMinimumHeight(label->fontMetrics().lineSpacing() + LINE_SPACING_OFFSET); |
||||
|
||||
// Set dark background for >windows
|
||||
//QColor toxDarkAsMySoul(28,28,28);
|
||||
//QPalette darkPal;
|
||||
//darkPal.setColor(QPalette::Window, toxDarkAsMySoul);
|
||||
//darkPal.setColor(QPalette::Base, toxDarkAsMySoul);
|
||||
//lineEdit->setPalette(darkPal);
|
||||
|
||||
connect(lineEdit, &EscLineEdit::editingFinished, this, &EditableLabelWidget::onLabelChangeSubmited); |
||||
connect(lineEdit, &EscLineEdit::escPressed, this, &EditableLabelWidget::onLabelChangeCancelled); |
||||
|
||||
addWidget(label); |
||||
addWidget(lineEdit); |
||||
|
||||
setCurrentWidget(label); |
||||
} |
||||
|
||||
void EditableLabelWidget::setText(const QString& text) |
||||
{ |
||||
label->setText(text); |
||||
lineEdit->setText(text); |
||||
} |
||||
|
||||
QString EditableLabelWidget::text() |
||||
{ |
||||
return label->text(); |
||||
} |
||||
|
||||
void EditableLabelWidget::onLabelChangeSubmited() |
||||
{ |
||||
if (isSubmitting) { |
||||
return; |
||||
} |
||||
isSubmitting = true; |
||||
|
||||
QString oldText = label->text(); |
||||
QString newText = lineEdit->text(); |
||||
// `lineEdit->clearFocus()` triggers `onLabelChangeSubmited()`, we use `isSubmitting` as a workaround
|
||||
lineEdit->clearFocus(); |
||||
setCurrentWidget(label); |
||||
|
||||
if (oldText != newText) { |
||||
label->setText(newText); |
||||
emit textChanged(newText, oldText); |
||||
} |
||||
|
||||
isSubmitting = false; |
||||
} |
||||
|
||||
void EditableLabelWidget::onLabelChangeCancelled() |
||||
{ |
||||
// order of calls matters, since clearFocus() triggers EditableLabelWidget::onLabelChangeSubmited()
|
||||
lineEdit->setText(label->text()); |
||||
lineEdit->clearFocus(); |
||||
setCurrentWidget(label); |
||||
} |
||||
|
||||
void EditableLabelWidget::onLabelClicked() |
||||
{ |
||||
setCurrentWidget(lineEdit); |
||||
lineEdit->setFocus(); |
||||
} |
@ -1,66 +0,0 @@
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com> |
||||
|
||||
This file is part of Tox Qt GUI. |
||||
|
||||
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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#ifndef EDITABLELABELWIDGET_HPP |
||||
#define EDITABLELABELWIDGET_HPP |
||||
|
||||
#include "copyableelidelabel.h" |
||||
#include "esclineedit.h" |
||||
|
||||
#include <QLineEdit> |
||||
#include <QStackedWidget> |
||||
|
||||
class ClickableCopyableElideLabel : public CopyableElideLabel |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
explicit ClickableCopyableElideLabel(QWidget* parent = 0); |
||||
|
||||
protected: |
||||
bool event(QEvent* event) Q_DECL_OVERRIDE; |
||||
|
||||
signals: |
||||
void clicked(); |
||||
|
||||
}; |
||||
|
||||
class EditableLabelWidget : public QStackedWidget |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
explicit EditableLabelWidget(QWidget* parent = 0); |
||||
|
||||
ClickableCopyableElideLabel* label; |
||||
EscLineEdit* lineEdit; |
||||
|
||||
void setText(const QString& text); |
||||
QString text(); |
||||
|
||||
private: |
||||
static const int LINE_SPACING_OFFSET = 2; |
||||
bool isSubmitting; |
||||
|
||||
private slots: |
||||
void onLabelChangeSubmited(); |
||||
void onLabelChangeCancelled(); |
||||
void onLabelClicked(); |
||||
|
||||
signals: |
||||
void textChanged(QString newText, QString oldText); |
||||
|
||||
}; |
||||
|
||||
#endif // EDITABLELABELWIDGET_HPP
|
@ -1,82 +0,0 @@
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com> |
||||
|
||||
This file is part of Tox Qt GUI. |
||||
|
||||
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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#include "elidelabel.h" |
||||
|
||||
#include <QPainter> |
||||
#include <QEvent> |
||||
|
||||
ElideLabel::ElideLabel(QWidget *parent) : |
||||
QLabel(parent), _textElide(false), _textElideMode(Qt::ElideNone), _showToolTipOnElide(false) |
||||
{ |
||||
} |
||||
|
||||
void ElideLabel::paintEvent(QPaintEvent *event) |
||||
{ |
||||
QFrame::paintEvent(event); |
||||
QPainter p(this); |
||||
QFontMetrics metrics(font()); |
||||
if ((metrics.width(text()) > contentsRect().width()) && textElide()) { |
||||
QString elidedText = fontMetrics().elidedText(text(), textElideMode(), rect().width()); |
||||
p.drawText(rect(), alignment(), elidedText); |
||||
} else { |
||||
QLabel::paintEvent(event); |
||||
} |
||||
} |
||||
|
||||
bool ElideLabel::event(QEvent *event) |
||||
{ |
||||
if (event->type() == QEvent::ToolTip) { |
||||
QFontMetrics metrics(font()); |
||||
if ((metrics.width(text()) > contentsRect().width()) && textElide() && showToolTipOnElide()) { |
||||
setToolTip(text()); |
||||
} else { |
||||
setToolTip(""); |
||||
} |
||||
} |
||||
|
||||
return QLabel::event(event); |
||||
} |
||||
|
||||
void ElideLabel::setTextElide(bool set) |
||||
{ |
||||
_textElide = set; |
||||
} |
||||
|
||||
bool ElideLabel::textElide() const |
||||
{ |
||||
return _textElide; |
||||
} |
||||
|
||||
void ElideLabel::setTextElideMode(Qt::TextElideMode mode) |
||||
{ |
||||
_textElideMode = mode; |
||||
} |
||||
|
||||
Qt::TextElideMode ElideLabel::textElideMode() const |
||||
{ |
||||
return _textElideMode; |
||||
} |
||||
|
||||
void ElideLabel::setShowToolTipOnElide(bool show) |
||||
{ |
||||
_showToolTipOnElide = show; |
||||
} |
||||
|
||||
bool ElideLabel::showToolTipOnElide() |
||||
{ |
||||
return _showToolTipOnElide; |
||||
} |
@ -1,50 +0,0 @@
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com> |
||||
|
||||
This file is part of Tox Qt GUI. |
||||
|
||||
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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#ifndef ELIDELABEL_HPP |
||||
#define ELIDELABEL_HPP |
||||
|
||||
#include <QLabel> |
||||
|
||||
class ElideLabel : public QLabel |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
explicit ElideLabel(QWidget *parent = 0); |
||||
|
||||
void setTextElide(bool set); |
||||
bool textElide() const; |
||||
|
||||
void setTextElideMode(Qt::TextElideMode mode); |
||||
Qt::TextElideMode textElideMode() const; |
||||
|
||||
void setShowToolTipOnElide(bool show); |
||||
bool showToolTipOnElide(); |
||||
|
||||
protected: |
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; |
||||
bool event(QEvent *e) Q_DECL_OVERRIDE; |
||||
|
||||
private: |
||||
bool _textElide; |
||||
Qt::TextElideMode _textElideMode; |
||||
|
||||
bool _showToolTipOnElide; |
||||
|
||||
|
||||
}; |
||||
|
||||
#endif // ELIDELABEL_HPP
|
@ -1,34 +0,0 @@
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com> |
||||
|
||||
This file is part of Tox Qt GUI. |
||||
|
||||
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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#include "esclineedit.h" |
||||
|
||||
#include <QKeyEvent> |
||||
#include <QMouseEvent> |
||||
|
||||
EscLineEdit::EscLineEdit(QWidget* parent) : |
||||
QLineEdit(parent) |
||||
{ |
||||
} |
||||
|
||||
void EscLineEdit::keyPressEvent(QKeyEvent* event) |
||||
{ |
||||
if (event->key() == Qt::Key_Escape && event->modifiers() == Qt::NoModifier) { |
||||
emit escPressed(); |
||||
} else { |
||||
QLineEdit::keyPressEvent(event); |
||||
} |
||||
} |
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2013 by Maxim Biro <nurupo.contributions@gmail.com> |
||||
|
||||
This file is part of Tox Qt GUI. |
||||
|
||||
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 |
||||
(at your option) 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 COPYING file for more details. |
||||
*/ |
||||
|
||||
#ifndef ESCLINEEDIT_HPP |
||||
#define ESCLINEEDIT_HPP |
||||
|
||||
#include <QLineEdit> |
||||
|
||||
class EscLineEdit : public QLineEdit |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
explicit EscLineEdit(QWidget* parent); |
||||
|
||||
protected: |
||||
void keyPressEvent(QKeyEvent* event) Q_DECL_OVERRIDE; |
||||
|
||||
signals: |
||||
void escPressed(); |
||||
|
||||
}; |
||||
|
||||
#endif // ESCLINEEDIT_HPP
|
Loading…
Reference in new issue