summaryrefslogtreecommitdiffstats
path: root/examples/widgets/browser/squeezelabel.cpp
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-08-05 16:37:31 +0200
committerJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-08-20 18:15:09 +0200
commitccfeac7d1e474408e2cae169714326f6198eb17c (patch)
tree56d245e3277c2a455589f7d30b3bff9e5a8fb5b7 /examples/widgets/browser/squeezelabel.cpp
parent0498dc995ddac96009c5ef496545cdd6f49f367f (diff)
Import the demo browser into widget examples.
Import the sources as-is, without adding it to the build, to allow performing diffs later on the changes that were needed to port it to use QtWebEngine and manage source compatibility issues. Change-Id: Icf8a284881ce2153e9b5a1ba97dbe77096f1b88d Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'examples/widgets/browser/squeezelabel.cpp')
-rw-r--r--examples/widgets/browser/squeezelabel.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/examples/widgets/browser/squeezelabel.cpp b/examples/widgets/browser/squeezelabel.cpp
new file mode 100644
index 000000000..c40fe97da
--- /dev/null
+++ b/examples/widgets/browser/squeezelabel.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "squeezelabel.h"
+
+SqueezeLabel::SqueezeLabel(QWidget *parent) : QLabel(parent)
+{
+}
+
+void SqueezeLabel::paintEvent(QPaintEvent *event)
+{
+ QFontMetrics fm = fontMetrics();
+ if (fm.width(text()) > contentsRect().width()) {
+ QString elided = fm.elidedText(text(), Qt::ElideMiddle, width());
+ QString oldText = text();
+ setText(elided);
+ QLabel::paintEvent(event);
+ setText(oldText);
+ } else {
+ QLabel::paintEvent(event);
+ }
+}