QString textLabelForData(const QVariantMap &data, const QFont &font, const QString &format, bool escapeAmpersands, int maxWidthPixels, int maxLines) { QString label; const QString notes = data.value(mimeItemNotes).toString(); if ( data.contains(mimeHidden) ) { label = QObject::tr("<HIDDEN>", "Label for hidden/secret clipboard content"); } else if ( data.contains(mimeText) || data.contains(mimeUriList) ) { const QString text = getTextData(data); const int n = text.count(QChar('\n')) + 1; if (n > 1) label = QObject::tr("%1 (%n lines)", "Label for multi-line text in clipboard", n); else label = QString("%1"); if (!format.isEmpty()) label = format.arg(label); const QString textWithNotes = notes.isEmpty() ? text : notes + ": " + text; return elideText(textWithNotes, font, label, escapeAmpersands, maxWidthPixels, maxLines); } else if ( findFormatsWithPrefix(true, "image/", data) ) { label = QObject::tr("<IMAGE>", "Label for image in clipboard"); } else if ( data.contains(mimeItems) ) { label = QObject::tr("<ITEMS>", "Label for copied items in clipboard"); } else if ( findFormatsWithPrefix(false, COPYQ_MIME_PREFIX, data) ) { label = QObject::tr("<EMPTY>", "Label for empty clipboard"); } else { label = QObject::tr("<DATA>", "Label for data in clipboard"); } if (!notes.isEmpty()) { label = elideText(notes, font, QString(), escapeAmpersands, maxWidthPixels, maxLines) + ": " + label; } if (!format.isEmpty()) label = format.arg(label); return label; }
void SubWindow::adjustTitleBar() { // button adjustments m_maximizeBtn->hide(); m_restoreBtn->hide(); const int rightSpace = 3; const int buttonGap = 1; const int menuButtonSpace = 24; QPoint rightButtonPos( width() - rightSpace - m_buttonSize.width(), 3 ); QPoint middleButtonPos( width() - rightSpace - ( 2 * m_buttonSize.width() ) - buttonGap, 3 ); QPoint leftButtonPos( width() - rightSpace - ( 3 * m_buttonSize.width() ) - ( 2 * buttonGap ), 3 ); // the buttonBarWidth depends on the number of buttons. // we need it to calculate the width of window title label int buttonBarWidth = rightSpace + m_buttonSize.width(); // set the buttons on their positions. // the close button is always needed and on the rightButtonPos m_closeBtn->move( rightButtonPos ); // here we ask: is the Subwindow maximizable and // then we set the buttons and show them if needed if( windowFlags() & Qt::WindowMaximizeButtonHint ) { buttonBarWidth = buttonBarWidth + m_buttonSize.width() + buttonGap; m_maximizeBtn->move( middleButtonPos ); m_restoreBtn->move( middleButtonPos ); m_maximizeBtn->setHidden( isMaximized() ); } // we're keeping the restore button around if we open projects // from older versions that have saved minimized windows m_restoreBtn->setVisible( isMaximized() || isMinimized() ); // title QLabel adjustments m_windowTitle->setAlignment( Qt::AlignHCenter ); m_windowTitle->setFixedWidth( widget()->width() - ( menuButtonSpace + buttonBarWidth ) ); m_windowTitle->move( menuButtonSpace, ( m_titleBarHeight / 2 ) - ( m_windowTitle->sizeHint().height() / 2 ) - 1 ); // if minimized we can't use widget()->width(). We have to hard code the width, // as the width of all minimized windows is the same. if( isMinimized() ) { m_restoreBtn->move( m_maximizeBtn->isHidden() ? middleButtonPos : leftButtonPos ); m_windowTitle->setFixedWidth( 120 ); } // truncate the label string if the window is to small. Adds "..." elideText( m_windowTitle, widget()->windowTitle() ); m_windowTitle->setTextInteractionFlags( Qt::NoTextInteraction ); m_windowTitle->adjustSize(); }
void ActionHandler::closeAction(Action *action) { QString msg; QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information; if ( action->actionFailed() ) { msg += tr("Error: %1\n").arg(action->errorString()) + action->errorOutput(); icon = QSystemTrayIcon::Critical; } else if ( action->exitCode() != 0 ) { msg += tr("Exit code: %1\n").arg(action->exitCode()) + action->errorOutput(); icon = QSystemTrayIcon::Warning; } else if ( !action->inputFormats().isEmpty() ) { QModelIndex index = action->index(); ClipboardBrowser *c = m_wnd->browserForItem(index); if (c) { QStringList removeFormats = action->inputFormats(); removeFormats.removeAll( action->outputFormat() ); if ( !removeFormats.isEmpty() ) c->model()->setData(index, removeFormats, contentType::removeFormats); } } if ( !msg.isEmpty() ) { const int maxWidthPoints = ConfigurationManager::instance()->value("notification_maximum_width").toInt(); const QString command = action->command() .replace("copyq eval --", "copyq:"); const QString name = QString(command).replace('\n', " "); const QString format = tr("Command %1").arg(quoteString("%1")); const QString title = elideText(name, QFont(), format, pointsToPixels(maxWidthPoints)); msg.append("\n---\n" + command + "\n---"); m_wnd->showMessage(title, msg, icon); } m_activeActionDialog->actionFinished(action); Q_ASSERT(m_actionCounter > 0); --m_actionCounter; emit runningActionsCountChanged(); action->deleteLater(); }
void ElidedLabel::setText( const QString& text ) { m_text = text; elideText(); }
void ElidedLabel::resizeEvent( QResizeEvent* e ) { elideText(); QLabel::resizeEvent( e ); }
void ElidingButton::setText( const QString &text ) { m_fullText = text; elideText( size() ); // elideText will call QPushButton::setText() }
void ElidingButton::resizeEvent( QResizeEvent *event ) { elideText( event->size() ); QPushButton::resizeEvent( event ); }