* Right align right column.

"Transport" or "comment" text does not get truncated anymore,
  when it is longer than "pending jobs" text.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36896 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2010-05-22 07:27:21 +00:00
parent d1dd67cbbf
commit 0514b0cad2
2 changed files with 86 additions and 13 deletions
+67 -9
View File
@@ -36,6 +36,8 @@ PrinterListView::PrinterListView(BRect frame)
fFolder(NULL), fFolder(NULL),
fActivePrinter(NULL) fActivePrinter(NULL)
{ {
fLayoutData.fLeftColumnMaximumWidth = 100;
fLayoutData.fRightColumnMaximumWidth = 100;
} }
@@ -65,8 +67,10 @@ PrinterListView::BuildPrinterList()
BEntry entry; BEntry entry;
while(dir.GetNextEntry(&entry) == B_OK) { while(dir.GetNextEntry(&entry) == B_OK) {
BDirectory printer(&entry); BDirectory printer(&entry);
_AddPrinter(printer); _AddPrinter(printer, false);
} }
_LayoutPrinterItems();
} }
@@ -147,7 +151,7 @@ PrinterListView::SelectedItem() const
void void
PrinterListView::_AddPrinter(BDirectory& printer) PrinterListView::_AddPrinter(BDirectory& printer, bool calculateLayout)
{ {
BString state; BString state;
node_ref node; node_ref node;
@@ -164,12 +168,38 @@ PrinterListView::_AddPrinter(BDirectory& printer)
if (info.GetType(buffer) == B_OK if (info.GetType(buffer) == B_OK
&& strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) { && strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) {
// Yes, it is a printer definition node // Yes, it is a printer definition node
AddItem(new PrinterItem(dynamic_cast<PrintersWindow*>(Window()), printer)); AddItem(new PrinterItem(dynamic_cast<PrintersWindow*>(Window()),
printer, fLayoutData));
if (calculateLayout)
_LayoutPrinterItems();
} }
} }
} }
void
PrinterListView::_LayoutPrinterItems()
{
float& leftColumnMaximumWidth = fLayoutData.fLeftColumnMaximumWidth;
float& rightColumnMaximumWidth = fLayoutData.fRightColumnMaximumWidth;
for (int32 i = 0; i < CountItems(); i ++) {
PrinterItem* item = dynamic_cast<PrinterItem*>(ItemAt(i));
float leftColumnWidth = 0;
float rightColumnWidth = 0;
item->GetColumnWidth(this, leftColumnWidth, rightColumnWidth);
leftColumnMaximumWidth = MAX(leftColumnMaximumWidth,
leftColumnWidth);
rightColumnMaximumWidth = MAX(rightColumnMaximumWidth,
rightColumnWidth);
}
Invalidate();
}
PrinterItem* PrinterItem*
PrinterListView::_FindItem(node_ref* node) const PrinterListView::_FindItem(node_ref* node) const
{ {
@@ -187,7 +217,7 @@ void
PrinterListView::_EntryCreated(node_ref* node, entry_ref* entry) PrinterListView::_EntryCreated(node_ref* node, entry_ref* entry)
{ {
BDirectory printer(node); BDirectory printer(node);
_AddPrinter(printer); _AddPrinter(printer, true);
} }
@@ -209,7 +239,7 @@ void
PrinterListView::_AttributeChanged(node_ref* node) PrinterListView::_AttributeChanged(node_ref* node)
{ {
BDirectory printer(node); BDirectory printer(node);
_AddPrinter(printer); _AddPrinter(printer, true);
} }
@@ -222,10 +252,12 @@ BBitmap* PrinterItem::sIcon = NULL;
BBitmap* PrinterItem::sSelectedIcon = NULL; BBitmap* PrinterItem::sSelectedIcon = NULL;
PrinterItem::PrinterItem(PrintersWindow* window, const BDirectory& node) PrinterItem::PrinterItem(PrintersWindow* window, const BDirectory& node,
PrinterListLayoutData& layoutData)
: BListItem(0, false), : BListItem(0, false),
fFolder(NULL), fFolder(NULL),
fNode(node) fNode(node),
fLayoutData(layoutData)
{ {
BRect rect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1); BRect rect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1);
if (sIcon == NULL) { if (sIcon == NULL) {
@@ -287,6 +319,21 @@ PrinterItem::~PrinterItem()
} }
void
PrinterItem::GetColumnWidth(BView* view, float& leftColumn, float& rightColumn)
{
BFont font;
view->GetFont(&font);
leftColumn = font.StringWidth(fName.String());
leftColumn = MAX(leftColumn, font.StringWidth(fDriverName.String()));
rightColumn = font.StringWidth(fPendingJobs.String());
rightColumn = MAX(rightColumn, font.StringWidth(fTransport.String()));
rightColumn = MAX(rightColumn, font.StringWidth(fComments.String()));
}
void void
PrinterItem::Update(BView *owner, const BFont *font) PrinterItem::Update(BView *owner, const BFont *font)
{ {
@@ -348,13 +395,24 @@ PrinterItem::DrawItem(BView *owner, BRect /*bounds*/, bool complete)
owner->SetLowColor(oldLowColor); owner->SetLowColor(oldLowColor);
owner->SetHighColor(oldHighColor); owner->SetHighColor(oldHighColor);
float x = B_LARGE_ICON + 8.0; float iconColumnWidth = B_LARGE_ICON + 8.0;
float x = iconColumnWidth;
BPoint iconPt(bounds.LeftTop() + BPoint(2.0, 2.0)); BPoint iconPt(bounds.LeftTop() + BPoint(2.0, 2.0));
BPoint namePt(iconPt + BPoint(x, fntheight)); BPoint namePt(iconPt + BPoint(x, fntheight));
BPoint driverPt(iconPt + BPoint(x, fntheight * 2.0)); BPoint driverPt(iconPt + BPoint(x, fntheight * 2.0));
BPoint defaultPt(iconPt + BPoint(x, fntheight * 3.0)); BPoint defaultPt(iconPt + BPoint(x, fntheight * 3.0));
float width = owner->StringWidth(B_TRANSLATE("No pending jobs.")); float totalWidth = bounds.Width() - iconColumnWidth;
float maximumWidth = fLayoutData.fLeftColumnMaximumWidth +
fLayoutData.fRightColumnMaximumWidth;
float width;
if (totalWidth < maximumWidth) {
width = fLayoutData.fRightColumnMaximumWidth * totalWidth /
maximumWidth;
} else {
width = fLayoutData.fRightColumnMaximumWidth;
}
BPoint pendingPt(bounds.right - width - 8.0, namePt.y); BPoint pendingPt(bounds.right - width - 8.0, namePt.y);
BPoint transportPt(bounds.right - width - 8.0, driverPt.y); BPoint transportPt(bounds.right - width - 8.0, driverPt.y);
BPoint commentPt(bounds.right - width - 8.0, defaultPt.y); BPoint commentPt(bounds.right - width - 8.0, defaultPt.y);
+18 -3
View File
@@ -25,6 +25,14 @@ class BBitmap;
class PrintersWindow; class PrintersWindow;
struct PrinterListLayoutData
{
float fLeftColumnMaximumWidth;
float fRightColumnMaximumWidth;
};
class PrinterListView : public BListView, public FolderListener { class PrinterListView : public BListView, public FolderListener {
public: public:
PrinterListView(BRect frame); PrinterListView(BRect frame);
@@ -43,7 +51,8 @@ public:
private: private:
typedef BListView Inherited; typedef BListView Inherited;
void _AddPrinter(BDirectory &printer); void _AddPrinter(BDirectory &printer, bool calculateLayout);
void _LayoutPrinterItems();
PrinterItem *_FindItem(node_ref* node) const; PrinterItem *_FindItem(node_ref* node) const;
void _EntryCreated(node_ref *node, void _EntryCreated(node_ref *node,
@@ -53,15 +62,20 @@ private:
FolderWatcher *fFolder; FolderWatcher *fFolder;
PrinterItem *fActivePrinter; PrinterItem *fActivePrinter;
PrinterListLayoutData fLayoutData;
}; };
class PrinterItem : public BListItem { class PrinterItem : public BListItem {
public: public:
PrinterItem(PrintersWindow *window, PrinterItem(PrintersWindow* window,
const BDirectory &node); const BDirectory& node,
PrinterListLayoutData& layoutData);
~PrinterItem(); ~PrinterItem();
void GetColumnWidth(BView* view, float& leftColumn,
float& rightColumn);
void DrawItem(BView *owner, BRect bounds, void DrawItem(BView *owner, BRect bounds,
bool complete); bool complete);
void Update(BView *owner, const BFont *font); void Update(BView *owner, const BFont *font);
@@ -87,6 +101,7 @@ private:
BString fDriverName; BString fDriverName;
BString fName; BString fName;
BString fPendingJobs; BString fPendingJobs;
PrinterListLayoutData& fLayoutData;
static BBitmap *sIcon; static BBitmap *sIcon;
static BBitmap *sSelectedIcon; static BBitmap *sSelectedIcon;