void Renamer::RenameList(BList* FileList) { fNumberOfItems = FileList->CountItems(); FileListItem* ListItem; for (int32 i = 0; i < fNumberOfItems; i++) { ListItem = (FileListItem*)FileList->ItemAt(i); ListItem->SetNewName(""); } }
void Renamer_Extension::RenameList(BList* FileList) { Renamer::RenameList(FileList); const bool replaceold = bool(fReplaceOldCheckBox->Value()); const int32 upperlower = fLowerCase->Value() == B_CONTROL_ON; FileListItem* ListItem; BMessage msg; const char* ExtensionString; BString Extension, NewName; int OldExtStart; for (int32 i = 0; i < fNumberOfItems; i++) { ListItem = (FileListItem*)FileList->ItemAt(i); if (BMimeType((char*)&ListItem->fMimeType).GetFileExtensions(&msg) == B_OK) { for (int32 j = 0; (msg.FindString("extensions", j, &ExtensionString) == B_OK); j++) { if (strlen(ExtensionString) < MAX_EXTENSION_LENGTH) { Extension = ExtensionString; Extension.Prepend("."); if (upperlower) Extension.ToLower(); else Extension.ToUpper(); NewName = ListItem->fName; if ((replaceold) && ((OldExtStart = NewName.FindLast(".")) > 0)) { ListItem->SetNewName(NewName .Truncate(OldExtStart).Append(Extension)); } else ListItem->SetNewName(NewName.Append(Extension)); break; } } } } };
void FileListDelegate::paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const { auto path = index.data(Qt::UserRole).toString(); FileListItem* item = fileListWidget->getItem(path); File* file = item->getFile(); auto bgRect = option.rect; bgRect.adjust(0, 0, -4, -37); auto textRect = QRect(bgRect.x() + 6, bgRect.bottom(), bgRect.width() - 12, 28); p->setPen(Qt::NoPen); // draw icon if (file->isFolder()) { if (file->isDotDot()) { drawPixmap(p, fileListWidget->backPixmap, bgRect, false); } else { drawPixmap(p, fileListWidget->folderPixmap, bgRect, false); } } else if (file->isImage()) { p->setBrush(backgroundBrush); p->drawRect(bgRect); } drawPixmap(p, item->pixmap, bgRect, file->isFolder() && !item->pixmap.isNull()); // draw selection if (item->isSelected()) { auto selRect = option.rect; selRect.adjust(0, 0, -4, -4); p->setBrush(selectionBrush); p->drawRect(selRect); } // draw text QString text = index.data().toString(); auto font = p->font(); QFontMetrics fontMetrics(font); auto elidedText = fontMetrics.elidedText(text, Qt::ElideMiddle, textRect.width()); p->setPen(textPen); p->drawText(textRect, Qt::AlignCenter, elidedText); }
void Renamer_Remove::RenameList(BList* FileList) { Renamer::RenameList(FileList); bool FromRight1 = bool(fDirection1->Menu() ->IndexOf(fDirection1->Menu()->FindMarked())); bool FromRight2 = bool(fDirection2->Menu() ->IndexOf(fDirection2->Menu()->FindMarked())); FileListItem* ListItem; BString ResultString, Part2; int EndPart1, StartPart2; int32 Position1 = fPosition1->Value(); int32 Position2 = fPosition2->Value(); int32 positionMaxValue = 0; int32 UTF_LengthOfFilename, LengthOfFilename; for (int i = 0; i < fNumberOfItems; i++) { ListItem = (FileListItem* )FileList->ItemAt(i); UTF_LengthOfFilename = LengthOfFilename = ListItem->fName.Length(); if (LengthOfFilename > positionMaxValue) positionMaxValue = LengthOfFilename; char* tempStr = new char[UTF_LengthOfFilename + 1]; convert_from_utf8(B_ISO1_CONVERSION, ListItem->fName.String(), &UTF_LengthOfFilename, tempStr, &LengthOfFilename, 0); tempStr[LengthOfFilename] = 0; if (FromRight1) { EndPart1 = (LengthOfFilename >= Position1) ? LengthOfFilename - Position1 : 0; } else { EndPart1 = (LengthOfFilename >= Position1) ? Position1 : LengthOfFilename; } if (FromRight2) { StartPart2 = (LengthOfFilename >= Position2) ? LengthOfFilename - Position2 : 0; } else { StartPart2 = (LengthOfFilename >= Position2) ? Position2 : LengthOfFilename; } if (StartPart2 < EndPart1) std::swap(StartPart2, EndPart1); ResultString.SetTo(tempStr, EndPart1); BString(tempStr).CopyInto(Part2, StartPart2, LengthOfFilename - StartPart2); ResultString.Append(Part2); LengthOfFilename = ResultString.Length(); UTF_LengthOfFilename = LengthOfFilename* 2; char* utf_String = new char[UTF_LengthOfFilename + 1]; convert_to_utf8(B_ISO1_CONVERSION, ResultString.String(), &LengthOfFilename, utf_String, &UTF_LengthOfFilename, 0); utf_String[UTF_LengthOfFilename] = 0; ListItem->SetNewName(utf_String); } fPosition1->SetMaxValue(positionMaxValue); fPosition2->SetMaxValue(positionMaxValue); }
// TODO margin void FileListItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { FileListItem *item = static_cast<FileListItem*>( index.internalPointer() ); QColor backgroundColor; painter->save(); QStyleOptionViewItem _option = option; bool isConverting = false; bool isFailed = false; if( item ) { switch( item->state ) { case FileListItem::WaitingForConversion: break; case FileListItem::Ripping: isConverting = true; break; case FileListItem::Converting: isConverting = true; break; case FileListItem::ApplyingReplayGain: isConverting = true; break; case FileListItem::WaitingForAlbumGain: break; case FileListItem::ApplyingAlbumGain: isConverting = true; break; case FileListItem::Stopped: switch( item->returnCode ) { case FileListItem::Succeeded: break; case FileListItem::SucceededWithProblems: break; case FileListItem::StoppedByUser: break; case FileListItem::BackendNeedsConfiguration: isFailed = true; break; case FileListItem::DiscFull: isFailed = true; break; case FileListItem::Skipped: break; case FileListItem::Failed: isFailed = true; break; } break; } } if( isConverting ) { if( option.state & QStyle::State_Selected ) { backgroundColor = QColor(215,102,102); // hsv: 0, 134, 215 } else { backgroundColor = QColor(255,234,234); // hsv: 0, 21, 255 } } else if( isFailed ) { if( option.state & QStyle::State_Selected ) { backgroundColor = QColor(235,154, 49); // hsv: 34, 202, 235 } else { backgroundColor = QColor(255,204,156); // hsv: 29, 99, 255 } } else { if( option.state & QStyle::State_Selected ) { backgroundColor = option.palette.highlight().color(); } else { backgroundColor = option.palette.base().color(); } } painter->fillRect( option.rect, backgroundColor ); int m_left, m_top, m_right, m_bottom; item->treeWidget()->getContentsMargins( &m_left, &m_top, &m_right, &m_bottom ); //QRect m_rect = QRect( option.rect.x()+m_left, option.rect.y()+m_top, option.rect.width()-m_left-m_right, option.rect.height()-m_top-m_bottom ); QRect m_rect = QRect( option.rect.x()+m_left, option.rect.y(), option.rect.width()-m_left-m_right, option.rect.height() ); if( index.column() == 1 || index.column() == 2 ) { QRect textRect = painter->boundingRect( QRect(), Qt::AlignLeft|Qt::TextSingleLine, item->text(index.column()) ); if ( textRect.width() < m_rect.width() ) { painter->drawText( m_rect, Qt::TextSingleLine|Qt::TextExpandTabs, item->text(index.column()) ); } else { //textRect = painter->boundingRect( QRect(), Qt::AlignLeft, "... " ); painter->drawText( m_rect, Qt::AlignRight|Qt::TextSingleLine|Qt::TextExpandTabs, item->text(index.column()) ); QLinearGradient linearGrad( QPoint(m_rect.x(),0), QPoint(m_rect.x()+15,0) ); linearGrad.setColorAt( 0, backgroundColor ); backgroundColor.setAlpha( 0 ); linearGrad.setColorAt( 1, backgroundColor ); painter->fillRect( m_rect.x(), m_rect.y(), 15, m_rect.height(), linearGrad ); } } else { painter->drawText( m_rect, Qt::TextSingleLine|Qt::TextExpandTabs, item->text(index.column()) ); } //QItemDelegate::paint( painter, _option, index ); painter->restore(); // int progress = (index.row() != 0 ? 100 / index.row() : 0); // // // draw your cool progress bar here // QStyleOptionProgressBar opt; // opt.rect = option.rect; // opt.minimum = 0; // opt.maximum = 100; // opt.progress = progress; // opt.text = QString("%1%").arg(progress); // opt.textVisible = true; // QApplication::style()->drawControl(QStyle::CE_ProgressBar, &opt, painter, 0); // maybe even let default implementation draw list item contents? // QItemDelegate::paint(painter, option, index); }
void PecoApp::DoIt() { if (NothingToDo()) return; FileListItem *ListItem; BAlert *myAlert = new BAlert(NULL, MESSAGE_REALLY_DOIT, STR_CONTINUE, STR_CANCEL); if (myAlert->Go() == 1) return; for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) { if (ListItem->fErrorStatus == 1 ) { BAlert *myAlert = new BAlert(NULL, MESSAGE_WILL_HAVE_PROBS, STR_CONTINUE, STR_CANCEL); if (myAlert->Go() == 1) return; break; } } bool noerror = true, nomoreerrors=false, canceled=false; fWindow->Lock(); fStatusBar->SetText(STATUS_RENAMING); fStatusBar->SetMaxValue(fList->CountItems()); BButton *okButton = (BButton *)fWindow->FindView("DoIt"); okButton->SetEnabled(false); BTextControl* pfadView = (BTextControl *)fWindow->FindView("pfadView"); BString Pfad(pfadView->Text()); fWindow->Unlock(); BString AlterName, NeuerName; BEntry Datei; for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) { fWindow->Lock(); fStatusBar->Update(1); fWindow->Unlock(); if (canceled) { ListItem->fErrorStatus=0; continue; } if (ListItem->fNewName.String() != "" ) { AlterName = Pfad; AlterName.Append("/").Append(ListItem->fName); NeuerName = Pfad; NeuerName.Append("/").Append(ListItem->fNewName); Datei.SetTo(AlterName.String()); if ( Datei.Rename(NeuerName.String()) != B_OK ) { ListItem->fErrorStatus=1; fWindow->Lock(); fListView->InvalidateItem(i); fWindow->Unlock(); if (!nomoreerrors) { noerror = false; BString ErrorMessage(MESSAGE_HAVE_PROBLEM); ErrorMessage.ReplaceFirst("%1", ListItem->fName.String()); ErrorMessage.ReplaceFirst("%2", ListItem->fNewName.String()); BAlert *myAlert = new BAlert(NULL, ErrorMessage.String(), STR_CANCEL, STR_CONTINUE, STR_CONTINUE_WO_MSG, B_WIDTH_AS_USUAL, B_WARNING_ALERT); int32 result = myAlert->Go(); if (result == 0) { canceled = true; continue; } if (result == 2) nomoreerrors = true; } } else { fWindow->Lock(); ListItem->SetName(ListItem->fNewName); ListItem->SetNewName(""); fListView->InvalidateItem(i); fWindow->Unlock(); } } } // NoRenamer(); fWindow->Lock(); fStatusBar->Reset(STATUS_STATUS); fWindow->Unlock(); if (noerror) MakeList(); else { fStatusBar->SetText(STATUS_DIDIT_BAD); BAlert *myAlert = new BAlert(NULL, MESSAGE_MARKED_FILES, STR_OK); myAlert->Go(); } }