29 #include <KIconLoader>
31 #include <KSqueezedTextLabel>
34 #include <kio/netaccess.h>
36 #include <QtGui/QFont>
37 #include <QtGui/QLabel>
38 #include <QtGui/QLayout>
39 #include <QtGui/QGridLayout>
46 :
QWidget( parent ), mTool( tool )
48 QVBoxLayout* baseLayout =
new QVBoxLayout(
this );
49 baseLayout->setMargin( 0 );
52 mIconLabel =
new QLabel(
this );
55 mIconLabel->setFixedHeight( KIconLoader::SizeEnormous );
56 mIconLabel->setMinimumWidth( KIconLoader::SizeEnormous );
57 mIconLabel->setAlignment( Qt::AlignHCenter );
58 baseLayout->addWidget( mIconLabel );
61 mDocumentTitleLabel =
new QLabel(
this );
62 QFont font = mDocumentTitleLabel->font();
64 mDocumentTitleLabel->setFont( font );
65 mDocumentTitleLabel->setAlignment( Qt::AlignHCenter );
66 mDocumentTitleLabel->setWordWrap(
true );
67 mDocumentTitleLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
68 baseLayout->addWidget( mDocumentTitleLabel );
71 KSeparator* separator =
new KSeparator( Qt::Horizontal,
this );
72 baseLayout->addWidget( separator );
75 QGridLayout *propertyGrid =
new QGridLayout();
76 propertyGrid->setColumnStretch( 0, 0 );
77 propertyGrid->setColumnStretch( 1, 1 );
79 int currentPropertyRow = 0;
82 QLabel* label =
new QLabel( i18n(
"Type:"),
this );
83 propertyGrid->addWidget( label, currentPropertyRow, 0, Qt::AlignRight);
85 mMimeTypeLabel =
new QLabel( QString(),
this );
86 propertyGrid->addWidget( mMimeTypeLabel, currentPropertyRow++, 1);
89 label =
new QLabel( i18n(
"Location:"),
this );
90 propertyGrid->addWidget( label, currentPropertyRow, 0, Qt::AlignRight);
92 mLocationLabel =
new KSqueezedTextLabel(
this );
94 mLocationLabel->setLayoutDirection( Qt::LeftToRight );
97 if( layoutDirection() == Qt::RightToLeft )
98 mLocationLabel->setAlignment( Qt::AlignRight );
101 mLocationLabel->setTextInteractionFlags( Qt::TextInteractionFlags(Qt::TextSelectableByMouse|Qt::TextSelectableByKeyboard) );
102 propertyGrid->addWidget( mLocationLabel, currentPropertyRow++, 1 );
105 label =
new QLabel( i18n(
"Size:"),
this );
106 propertyGrid->addWidget( label, currentPropertyRow, 0, Qt::AlignRight );
108 mSizeLabel =
new QLabel(
this );
109 propertyGrid->addWidget( mSizeLabel, currentPropertyRow++, 1 );
112 label =
new QLabel( i18n(
"Created/Loaded:"),
this );
113 propertyGrid->addWidget( label, currentPropertyRow, 0, Qt::AlignRight);
114 currentPropertyRow++;
116 label =
new QLabel( i18n(
"Last modified:"),
this );
117 propertyGrid->addWidget( label, currentPropertyRow, 0, Qt::AlignRight);
118 currentPropertyRow++;
120 label =
new QLabel( i18n(
"Last synchronized:"),
this );
121 propertyGrid->addWidget( label, currentPropertyRow, 0, Qt::AlignRight);
122 currentPropertyRow++;
128 label =
new QLabel(i18n(
"Created:"),
this );
129 propertyGrid->addWidget(label, currentPropertyRow, 0, Qt::AlignRight);
131 label =
new QLabel(KGlobal::locale()->formatDateTime(dt),
this );
132 propertyGrid->addWidget(label, currentPropertyRow++, 2);
136 baseLayout->addLayout( propertyGrid );
137 baseLayout->addStretch( 10 );
139 connect( mTool, SIGNAL(documentTitleChanged(QString)),
140 SLOT(onDocumentTitleChanged(QString)) );
141 connect( mTool, SIGNAL(documentMimeTypeChanged(KMimeType::Ptr)),
142 SLOT(onMimeTypeChanged(KMimeType::Ptr)) );
143 connect( mTool, SIGNAL(locationChanged(QString)),
144 SLOT(onLocationChanged(QString)) );
145 connect( mTool, SIGNAL(documentSizeChanged(
int)),
146 SLOT(onDocumentSizeChanged(
int)) );
148 onMimeTypeChanged( mTool->
mimeType() );
149 onLocationChanged( mTool->
location() );
154 void DocumentInfoView::onDocumentTitleChanged(
const QString& documentTitle )
156 mDocumentTitleLabel->setText( documentTitle );
159 void DocumentInfoView::onMimeTypeChanged( KMimeType::Ptr mimeTypePtr )
161 QString mimeTypeComment;
162 QPixmap mimeTypeIcon;
164 if( mimeTypePtr.isNull() )
166 mimeTypeComment = QLatin1String(
"-" );
171 mimeTypeComment = mimeTypePtr->comment();
172 mimeTypeIcon = KIconLoader::global()->loadIcon( mimeTypePtr->iconName(), KIconLoader::Desktop, KIconLoader::SizeEnormous );
175 mIconLabel->setPixmap( mimeTypeIcon );
176 mMimeTypeLabel->setText( mimeTypeComment );
179 void DocumentInfoView::onLocationChanged(
const QString& location )
181 const QString entry = location.isEmpty() ?
182 i18nc(
"There is no storage location assigned to yet.",
"[None]" ) :
184 mLocationLabel->setText( entry );
187 void DocumentInfoView::onDocumentSizeChanged(
int newSize )
189 const QString size = ( newSize != -1 ) ?
190 QString::fromLatin1(
"%1 (%2)" )
191 .arg( KIO::convertSize(newSize) )
192 .arg( KGlobal::locale()->formatNumber(newSize, 0) ) :
193 QString::fromLatin1(
"-" );
194 mSizeLabel->setText( size );
virtual ~DocumentInfoView()
DocumentInfoView(DocumentInfoTool *tool, QWidget *parent=0)