Skip to content

Commit

Permalink
SuperStart Computer shows graphical disk usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusbritanicus committed Oct 8, 2017
1 parent 8f9c584 commit a667c32
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 284 deletions.
183 changes: 20 additions & 163 deletions app/Gui/ModelViews/Views/IconView/NBIconDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,168 +462,6 @@ void NBIconDelegate::paintDetails( QPainter *painter, const NBStyleOptionViewIte
}
};

void NBIconDelegate::paintSuperStartIcons( QPainter *painter, const NBStyleOptionViewItem &option, const QModelIndex &index ) const {

maxLines = 1;
textLines = 1;

if ( index.column() != 0 )
QItemDelegate::paint( painter, option, index );

else {
// const NBItemViewModel *model = static_cast<const NBItemViewModel*>( index.model() );

QRect optionRect( option.rect );

/* Font Mentrics for elided text */
QFontMetrics fm( qApp->font() );

/* Get icon size */
QSize iconSize( option.decorationSize );

/* Text to be displayed */
QString text = index.data( Qt::DisplayRole ).toString();

/* Icon to be painted */
QPixmap icon;
if ( option.state & QStyle::State_Selected )
icon = index.data( Qt::DecorationRole ).value<QIcon>().pixmap( iconSize, QIcon::Selected );

else if ( option.state & QStyle::State_MouseOver )
icon = index.data( Qt::DecorationRole ).value<QIcon>().pixmap( iconSize, QIcon::Active );

else
icon = index.data( Qt::DecorationRole ).value<QIcon>().pixmap( iconSize, QIcon::Normal );

if ( ( icon.size().width() > iconSize.width() ) or ( icon.size().height() > iconSize.height() ) )
icon = icon.scaled( iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation );

/* Icon Size */
QSize iSize( icon.size() );

/*
*
* In this case, we need to center the image horizontally and vertically.
* +------------------------+
* | +--------+ |
* | | | |
* | | icon | |
* | | | |
* | +--------+ |
* | This is the text |
* +------------------------+
*
*/

// Icon padding
int padding = ( int ) round( iconSize.width() * 0.1 );

QRect textRect;
// Horizontal Centering, so don't bother
textRect.setX( optionRect.x() + padding );
// Original Y + Image Height + Image Padding Top + Text-Image Padding ( max = 3 )
textRect.setY( optionRect.y() + padding + qMin( 3, padding / 2 ) + iconSize.height() );
// Left and Right Border
textRect.setSize( optionRect.size() - QSize( 2 * padding, qMin( 3, padding / 2 ) + padding + iconSize.height() ) );

// Set elided text
text = fm.elidedText( text, Qt::ElideRight, textRect.width() );
if ( iconSize.width() <= 40 ) {
maxLines = 1;
textRect.adjust( 0, 3, 0, 0 );
}
else if ( iconSize.width() <= 60 ) {
maxLines = 2;
}
else if ( iconSize.width() <= 80 ) {
maxLines = 3;
}
else if ( iconSize.width() <= 100 ) {
maxLines = 4;
}
else if ( iconSize.width() < 120 ) {
maxLines = 5;
}
else {
maxLines = 6;
}

/* Icon rect */
QRect iconRect;
// Original X
iconRect.setX( optionRect.x() + ( optionRect.width() - iSize.width() ) / 2 );
// Original Y + Image Top Border + Height to make the image center of the icon rectangle
iconRect.setY( optionRect.y() + padding + ( iconSize.height() - iSize.height() ) / 2 );
// Icon Size
iconRect.setSize( iSize );

painter->save();

/* Antialiasing for rounded rect */
painter->setRenderHint( QPainter::Antialiasing, true );

/* Selection painter settings */
painter->setPen( QPen( Qt::NoPen ) );
if ( ( option.state & QStyle::State_Selected ) and ( option.state & QStyle::State_MouseOver ) )
painter->setBrush( option.palette.color( QPalette::Highlight ).darker( 125 ) );

else if ( option.state & QStyle::State_Selected )
painter->setBrush( option.palette.color( QPalette::Highlight ) );

else if ( option.state & QStyle::State_MouseOver )
painter->setBrush( option.palette.color( QPalette::Highlight ).lighter( 125 ) );

else
painter->setBrush( QBrush( Qt::transparent ) );

/* Selection rectangle */
painter->drawRoundedRect( optionRect.adjusted( padding / 2, padding / 2, -padding / 2, -padding / 2 ), 3, 3 );
painter->restore();

painter->save();
/* Focus Rectangle - In our case focus under line */
if ( option.state & QStyle::State_HasFocus ) {
painter->setBrush( Qt::NoBrush );
QPoint bl = optionRect.bottomLeft() + QPoint( 7, -padding / 2 );
QPoint br = optionRect.bottomRight() - QPoint( 7, padding / 2 );

QLinearGradient hLine( bl, br );

hLine.setColorAt( 0, Qt::transparent );
hLine.setColorAt( 0.3, option.palette.color( QPalette::BrightText ) );
hLine.setColorAt( 0.7, option.palette.color( QPalette::BrightText ) );
hLine.setColorAt( 1, Qt::transparent );

painter->setPen( QPen( QBrush( hLine ), 2 ) );
painter->drawLine( bl, br );
}
painter->restore();

// Paint Icon
painter->drawPixmap( iconRect, icon );

// Paint emblem
if ( option.nodeType == NBStyleOptionViewItem::SymLink )
painter->drawPixmap( QRect( iconRect.bottomRight() - QPoint( 16, 16 ), QSize( 16, 16 ) ), QIcon::fromTheme( "emblem-symbolic-link" ).pixmap( 16 ) );

else if ( option.nodeType == NBStyleOptionViewItem::Executable )
painter->drawPixmap( QRect( iconRect.bottomRight() - QPoint( 16, 16 ), QSize( 16, 16 ) ), QIcon::fromTheme( "application-x-executable" ).pixmap( 16 ) );

painter->save();
// Text Painter Settings
painter->setPen( option.palette.color( QPalette::Text ) );

// Draw Text
painter->drawText( textRect, Qt::AlignHCenter, text );

// Draw the extra details
painter->setPen( option.palette.color( QPalette::ButtonText ) );
paintIconTextDetails( painter, textRect, index );

painter->restore();
}
};

void NBIconDelegate::paintIconTextDetails( QPainter *painter, QRect &textRect, const QModelIndex &index ) const {

// The First Line is already drawn
Expand All @@ -641,7 +479,26 @@ void NBIconDelegate::paintIconTextDetails( QPainter *painter, QRect &textRect, c
/* One detail */
textRect.adjust( 0, lineSpacing + QFontInfo( qApp->font() ).pixelSize(), 0, 0 );
QString detail = index.data( Qt::UserRole + 1 ).toString();
painter->drawText( textRect, Qt::AlignHCenter, detail );
if ( not detail.endsWith( "% used" ) )
painter->drawText( textRect, Qt::AlignHCenter, detail );

else {
int used = detail.replace( "% used", "" ).toInt();
int x = textRect.x();
int y = textRect.y();
int w = textRect.width();
int h = textRect.height();
painter->save();
painter->setRenderHint( QPainter::Antialiasing, false );
painter->setPen( Qt::gray );
painter->drawRoundedRect( x + 10, y + h / 4, w - 20, h / 2, 2.0, 2.0 );
if ( used >= 90 )
painter->setBrush( Qt::darkRed );
else
painter->setBrush( Qt::darkGreen );
painter->drawRoundedRect( x + 10, y + h / 4, ( int )( ( w - 20. ) * used / 100 ), h / 2, 2.0, 2.0 );
painter->restore();
}
break;
}

Expand Down
2 changes: 0 additions & 2 deletions app/Gui/ModelViews/Views/IconView/NBIconDelegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class NBIconDelegate : public QItemDelegate {
void paintTiles( QPainter *painter, const NBStyleOptionViewItem &option, const QModelIndex &index ) const;
void paintDetails( QPainter *painter, const NBStyleOptionViewItem &option, const QModelIndex &index ) const;

void paintSuperStartIcons( QPainter *painter, const NBStyleOptionViewItem &option, const QModelIndex &index ) const;

private:
void paintIconTextDetails( QPainter *painter, QRect &textRect, const QModelIndex &index ) const;
void paintTileTextDetails( QPainter *painter, QRect &textRect, const QModelIndex &index ) const;
Expand Down
17 changes: 6 additions & 11 deletions app/Gui/ModelViews/Views/IconView/NBIconView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,19 +590,14 @@ void NBIconView::paintEvent( QPaintEvent* event ) {
option.palette = pltt;

NBIconDelegate *dlgt = qobject_cast<NBIconDelegate*>( itemDelegate() );
if ( cModel->modelDataType() == NBItemViewModel::SuperStart )
dlgt->paintSuperStartIcons( &painter, option, idx );

else {
if ( currentViewMode == QString( "Icons" ) )
dlgt->paintIcons( &painter, option, idx );
if ( currentViewMode == QString( "Icons" ) )
dlgt->paintIcons( &painter, option, idx );

else if ( currentViewMode == QString( "Tiles" ) )
dlgt->paintTiles( &painter, option, idx );
else if ( currentViewMode == QString( "Tiles" ) )
dlgt->paintTiles( &painter, option, idx );

else
dlgt->paintDetails( &painter, option, idx );
}
else
dlgt->paintDetails( &painter, option, idx );
}

painter.end();
Expand Down
108 changes: 0 additions & 108 deletions app/Vault/MicroDB/AbZip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,16 +1405,6 @@ void AbZip::setZipFileName( const QString& name ) {
};


void AbZip::setPassword( const QString& pw ) {

d_ptr->password = pw;
};

void AbZip::clearPassword( ) {

d_ptr->password.clear();
};

int AbZip::errorCode() const
{
return d_ptr->errorCode;
Expand All @@ -1439,38 +1429,11 @@ void AbZip::clearErrors() {



bool AbZip::setComment(const QString& comment) {

if ( d_ptr->isOpen() )
{
d_ptr->centralDir->endOfCentralDir.setComment( comment );
return true;
}
return false;
};

QString AbZip::getComment()const
{
return d_ptr->centralDir->endOfCentralDir.getComment();
};

ZipInfo AbZip::getInfo()const
{
return d_ptr->getInfo( );
};

void AbZip::setNameFilters( const QStringList& nameFilters ) {

d_ptr->nameFilters = nameFilters;
};

void AbZip::clearNameFilters( ) {

d_ptr->nameFilters.clear();
};



bool AbZip::addFile(const QString& file, const QString& root, AbZip::ZipOptions options, int level ) {

return d_ptr->addFile(file, root, options, level );
Expand Down Expand Up @@ -1499,79 +1462,8 @@ bool AbZip::writeFile(const QString& file, const QByteArray& data, AbZip::ZipOpt
return ret;
};

bool AbZip::addDirectory(const QString& srcPath, const QString& root, AbZip::ZipOptions options, int level ) {

return d_ptr->addDirectory( srcPath, root, options, level );
};

bool AbZip::addDirectory(const QString& srcPath, AbZip::ZipOptions options, int level ) {

return d_ptr->addDirectory( srcPath, QString(), options, level );
};


bool AbZip::extractFile(const QString& filename, const QString& destPath, AbZip::ZipOptions options) {

return d_ptr->extractFile(filename, destPath, options);
};


bool AbZip::extractFiles(const QStringList& listFiles, const QString& destPath, ZipOptions options) {

qint32 count = 0;
foreach( const QString& filename, listFiles)
{
if ( d_ptr->extractFile( filename, destPath, options ) )
count++;
else if ( !options.testFlag( AbZip::ContinueOnError ) )
return false;
};

return (count == listFiles.count()) ? true : false;
};


bool AbZip::deleteFile(const QString& filename, AbZip::ZipOptions options) {

return d_ptr->deleteFile(*this, filename, options);

};

bool AbZip::renameFile(const QString& oldFilename, const QString& newFilename, AbZip::ZipOptions options) {

return d_ptr->renameFile( oldFilename, newFilename, options);

};

bool AbZip::extractAll(const QString& path, AbZip::ZipOptions options) {

return d_ptr->extractAll(*this, path, QString(), options);
};

bool AbZip::extractAll(const QString& path, const QString& fromRoot, AbZip::ZipOptions options) {

return d_ptr->extractAll(*this, path, fromRoot, options);
};


QList<ZipFileInfo> AbZip::findFile( const QString& filename, ZipOptions options ) {

return d_ptr->findFile(*this, filename, QString(), options);
};

QList<ZipFileInfo> AbZip::findFile( const QString& filename, const QString& root, ZipOptions options ) {

return d_ptr->findFile(*this, filename, root, options);
};

bool AbZip::checkIntegrity() {

return d_ptr->checkIntegrity();

};

bool AbZip::repairArchive() {

return d_ptr->repairArchive();

};

0 comments on commit a667c32

Please sign in to comment.