1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #189 from krepa098/master

fixes
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-08-16 19:45:32 +02:00
commit 020e77330c
6 changed files with 106 additions and 8 deletions

View File

@ -88,7 +88,8 @@ HEADERS += widget/form/addfriendform.h \
smileypack.h \ smileypack.h \
widget/emoticonswidget.h \ widget/emoticonswidget.h \
style.h \ style.h \
widget/adjustingscrollarea.h widget/adjustingscrollarea.h \
widget/croppinglabel.h
SOURCES += \ SOURCES += \
widget/form/addfriendform.cpp \ widget/form/addfriendform.cpp \
@ -124,4 +125,5 @@ SOURCES += \
smileypack.cpp \ smileypack.cpp \
widget/emoticonswidget.cpp \ widget/emoticonswidget.cpp \
style.cpp \ style.cpp \
widget/adjustingscrollarea.cpp widget/adjustingscrollarea.cpp \
widget/croppinglabel.cpp

56
widget/croppinglabel.cpp Normal file
View File

@ -0,0 +1,56 @@
/*
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 "croppinglabel.h"
CroppingLabel::CroppingLabel(QWidget* parent)
: QLabel(parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
}
void CroppingLabel::setText(const QString& text)
{
origText = text;
setElidedText();
}
void CroppingLabel::resizeEvent(QResizeEvent* ev)
{
setElidedText();
QLabel::resizeEvent(ev);
}
QSize CroppingLabel::sizeHint() const
{
return QSize(0, QLabel::sizeHint().height());
}
QSize CroppingLabel::minimumSizeHint() const
{
return QSize(fontMetrics().width("..."), QLabel::minimumSizeHint().height());
}
void CroppingLabel::setElidedText()
{
QString elidedText = fontMetrics().elidedText(origText, Qt::ElideRight, width());
if (elidedText != origText)
setToolTip(origText);
else
setToolTip(QString());
QLabel::setText(elidedText);
}

40
widget/croppinglabel.h Normal file
View File

@ -0,0 +1,40 @@
/*
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 CROPPINGLABEL_H
#define CROPPINGLABEL_H
#include <QLabel>
class CroppingLabel : public QLabel
{
Q_OBJECT
public:
explicit CroppingLabel(QWidget *parent = 0);
virtual void setText(const QString& text);
virtual void resizeEvent(QResizeEvent *ev);
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;
protected:
void setElidedText();
private:
QString origText;
};
#endif // CROPPINGLABEL_H

View File

@ -179,12 +179,13 @@ void ChatForm::addFriendMessage(QString message)
void ChatForm::addMessage(QString author, QString message, QString date) void ChatForm::addMessage(QString author, QString message, QString date)
{ {
message = SmileyPack::getInstance().smileyfied(message);
addMessage(new QLabel(author), new QLabel(message), new QLabel(date)); addMessage(new QLabel(author), new QLabel(message), new QLabel(date));
} }
void ChatForm::addMessage(QLabel* author, QLabel* message, QLabel* date) void ChatForm::addMessage(QLabel* author, QLabel* message, QLabel* date)
{ {
message->setText(SmileyPack::getInstance().smileyfied(message->text()));
QScrollBar* scroll = chatArea->verticalScrollBar(); QScrollBar* scroll = chatArea->verticalScrollBar();
lockSliderToBottom = scroll && scroll->value() == scroll->maximum(); lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
author->setAlignment(Qt::AlignTop | Qt::AlignRight); author->setAlignment(Qt::AlignTop | Qt::AlignRight);

View File

@ -54,7 +54,6 @@ FriendWidget::FriendWidget(int FriendId, QString id)
this->setPalette(pal3); this->setPalette(pal3);
name.setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); name.setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
statusMessage.setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
textLayout.addStretch(); textLayout.addStretch();
textLayout.addWidget(&name); textLayout.addWidget(&name);
@ -65,7 +64,6 @@ FriendWidget::FriendWidget(int FriendId, QString id)
layout.addWidget(&avatar); layout.addWidget(&avatar);
layout.addSpacing(5); layout.addSpacing(5);
layout.addLayout(&textLayout); layout.addLayout(&textLayout);
layout.addStretch();
layout.addSpacing(5); layout.addSpacing(5);
layout.addWidget(&statusPic); layout.addWidget(&statusPic);
layout.addSpacing(5); layout.addSpacing(5);
@ -76,8 +74,6 @@ FriendWidget::FriendWidget(int FriendId, QString id)
layout.update(); layout.update();
layout.activate(); layout.activate();
updateGeometry(); updateGeometry();
qDebug() << "friend" << minimumSizeHint();
} }
void FriendWidget::mouseReleaseEvent (QMouseEvent*) void FriendWidget::mouseReleaseEvent (QMouseEvent*)

View File

@ -22,6 +22,8 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include "croppinglabel.h"
struct FriendWidget : public QWidget struct FriendWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -42,7 +44,8 @@ signals:
public: public:
int friendId; int friendId;
QLabel avatar, name, statusMessage, statusPic; QLabel avatar, name, statusPic;
CroppingLabel statusMessage;
QHBoxLayout layout; QHBoxLayout layout;
QVBoxLayout textLayout; QVBoxLayout textLayout;