File indexing completed on 2024-05-12 04:57:48
0001 /** 0002 * Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net> 0003 * 0004 * Redistribution and use in source and binary forms, with or without 0005 * modification, are permitted provided that the following conditions 0006 * are met: 0007 * 1. Redistributions of source code must retain the above copyright 0008 * notice, this list of conditions and the following disclaimer. 0009 * 2. Redistributions in binary form must reproduce the above copyright 0010 * notice, this list of conditions and the following disclaimer in the 0011 * documentation and/or other materials provided with the distribution. 0012 * 3. Neither the name of the Benjamin Meyer nor the names of its contributors 0013 * may be used to endorse or promote products derived from this software 0014 * without specific prior written permission. 0015 * 0016 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 0017 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0018 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0019 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 0020 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 0021 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 0022 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 0023 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 0024 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 0025 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 0026 * SUCH DAMAGE. 0027 */ 0028 0029 #include "squeezelabelv1.h" 0030 0031 SqueezeLabelV1::SqueezeLabelV1(QWidget* parent) 0032 : QLabel(parent) 0033 { 0034 } 0035 0036 void SqueezeLabelV1::paintEvent(QPaintEvent* event) 0037 { 0038 if (m_SqueezedTextCache != text()) { 0039 m_SqueezedTextCache = text(); 0040 QFontMetrics fm = fontMetrics(); 0041 if (fm.horizontalAdvance(m_SqueezedTextCache) > contentsRect().width()) { 0042 QString elided = fm.elidedText(text(), Qt::ElideMiddle, width()); 0043 setText(elided); 0044 } 0045 } 0046 0047 QLabel::paintEvent(event); 0048 }