mirror of
https://github.com/transmission/transmission
synced 2025-01-31 03:12:44 +00:00
Reduce initial torrent creation dialog size to minimum
Truncate text in path button to prevent width increase for long paths.
This commit is contained in:
parent
efddf08d67
commit
954a91ca39
3 changed files with 33 additions and 1 deletions
|
@ -220,6 +220,8 @@ MakeDialog::MakeDialog (Session& session, QWidget * parent):
|
|||
{
|
||||
ui.setupUi (this);
|
||||
|
||||
resize (minimumSizeHint ());
|
||||
|
||||
ui.destinationButton->setMode (TrPathButton::DirectoryMode);
|
||||
ui.destinationButton->setPath (QDir::homePath ());
|
||||
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
* $Id$
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileDialog>
|
||||
#include <QFileIconProvider>
|
||||
#include <QFileInfo>
|
||||
#include <QStyle>
|
||||
#include <QStyleOptionToolButton>
|
||||
#include <QStylePainter>
|
||||
|
||||
#include "path-button.h"
|
||||
#include "utils.h"
|
||||
|
@ -23,6 +26,7 @@ TrPathButton::TrPathButton (QWidget * parent):
|
|||
myPath ()
|
||||
{
|
||||
setSizePolicy(QSizePolicy (QSizePolicy::Preferred, QSizePolicy::Fixed));
|
||||
setText (tr ("(None)")); // for minimum width
|
||||
|
||||
updateAppearance ();
|
||||
|
||||
|
@ -71,6 +75,28 @@ TrPathButton::path () const
|
|||
return myPath;
|
||||
}
|
||||
|
||||
void
|
||||
TrPathButton::paintEvent (QPaintEvent * /*event*/)
|
||||
{
|
||||
QStylePainter painter(this);
|
||||
QStyleOptionToolButton option;
|
||||
initStyleOption (&option);
|
||||
|
||||
const QSize fakeContentSize (qMax (100, qApp->globalStrut ().width ()),
|
||||
qMax (100, qApp->globalStrut ().height ()));
|
||||
const QSize fakeSizeHint = style ()->sizeFromContents (QStyle::CT_ToolButton, &option, fakeContentSize, this);
|
||||
|
||||
int textWidth = width () - (fakeSizeHint.width () - fakeContentSize.width ()) - iconSize ().width () - 6;
|
||||
if (popupMode () == MenuButtonPopup)
|
||||
textWidth -= style ()->pixelMetric (QStyle::PM_MenuButtonIndicator, &option, this);
|
||||
|
||||
const QFileInfo pathInfo (myPath);
|
||||
option.text = myPath.isEmpty () ? tr ("(None)") : (pathInfo.fileName ().isEmpty () ? myPath : pathInfo.fileName ());
|
||||
option.text = fontMetrics ().elidedText (option.text, Qt::ElideMiddle, textWidth);
|
||||
|
||||
painter.drawComplexControl(QStyle::CC_ToolButton, option);
|
||||
}
|
||||
|
||||
void
|
||||
TrPathButton::onClicked ()
|
||||
{
|
||||
|
@ -110,8 +136,9 @@ TrPathButton::updateAppearance ()
|
|||
|
||||
setIconSize (QSize (iconSize, iconSize));
|
||||
setIcon (icon);
|
||||
setText (myPath.isEmpty () ? tr ("(None)") : (pathInfo.fileName ().isEmpty () ? myPath : pathInfo.fileName ()));
|
||||
setToolTip (myPath == text () ? QString () : myPath);
|
||||
|
||||
update ();
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -36,6 +36,9 @@ class TrPathButton: public QToolButton
|
|||
signals:
|
||||
void pathChanged (const QString& path);
|
||||
|
||||
protected:
|
||||
virtual void paintEvent (QPaintEvent * event);
|
||||
|
||||
private slots:
|
||||
void onClicked ();
|
||||
void onFileSelected (const QString& path);
|
||||
|
|
Loading…
Reference in a new issue