Make IconView icon_size:able. Adapt DataTranslations. Disable DataTranslation's info button on list deselection.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41248 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -5,21 +5,28 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <Mime.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
class IconView : public BView {
|
class IconView : public BView {
|
||||||
public:
|
public:
|
||||||
IconView(const BRect& frame, const char* name,
|
IconView(icon_size iconSize = B_LARGE_ICON);
|
||||||
uint32 resize, uint32 flags);
|
|
||||||
~IconView();
|
~IconView();
|
||||||
|
|
||||||
|
status_t InitCheck() const;
|
||||||
virtual void Draw(BRect area);
|
virtual void Draw(BRect area);
|
||||||
|
|
||||||
bool DrawIcon(bool draw);
|
void DrawIcon(bool draw);
|
||||||
bool SetIcon(const BPath& path);
|
status_t SetIcon(const BPath& path,
|
||||||
|
icon_size iconSize = B_LARGE_ICON);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _SetSize();
|
||||||
|
|
||||||
|
icon_size fIconSize;
|
||||||
BBitmap* fIconBitmap;
|
BBitmap* fIconBitmap;
|
||||||
bool fDrawIcon;
|
bool fDrawIcon;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "IconView.h"
|
#include "IconView.h"
|
||||||
|
|
||||||
|
#include <new>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -12,11 +13,14 @@
|
|||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
|
|
||||||
|
|
||||||
IconView::IconView(const BRect& frame, const char* name, uint32 resize,
|
using std::nothrow;
|
||||||
uint32 flags)
|
|
||||||
|
|
||||||
|
IconView::IconView(icon_size iconSize)
|
||||||
:
|
:
|
||||||
BView(frame, name, resize, flags),
|
BView("IconView", B_WILL_DRAW),
|
||||||
fIconBitmap(new BBitmap(BRect(B_LARGE_ICON), B_RGBA32)),
|
fIconSize(iconSize),
|
||||||
|
fIconBitmap(new BBitmap(BRect(iconSize), B_RGBA32)),
|
||||||
fDrawIcon(false)
|
fDrawIcon(false)
|
||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
@@ -30,45 +34,82 @@ IconView::~IconView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
status_t
|
||||||
IconView::SetIcon(const BPath& path)
|
IconView::SetIcon(const BPath& path, icon_size iconSize)
|
||||||
{
|
{
|
||||||
fDrawIcon = false;
|
fDrawIcon = false;
|
||||||
|
|
||||||
|
if (iconSize != fIconSize) {
|
||||||
|
BBitmap* bitmap = new BBitmap(BRect(iconSize), B_RGBA32);
|
||||||
|
if (bitmap == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
delete fIconBitmap;
|
||||||
|
fIconBitmap = bitmap;
|
||||||
|
fIconSize = iconSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t status = fIconBitmap->InitCheck();
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
BEntry entry(path.Path());
|
BEntry entry(path.Path());
|
||||||
BNode node(&entry);
|
BNode node(&entry);
|
||||||
BNodeInfo info(&node);
|
BNodeInfo info(&node);
|
||||||
|
|
||||||
if (info.GetTrackerIcon(fIconBitmap) != B_OK)
|
status = info.GetTrackerIcon(fIconBitmap, fIconSize);
|
||||||
return false;
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
if (!fIconBitmap->IsValid())
|
||||||
|
return fIconBitmap->InitCheck();
|
||||||
|
|
||||||
|
_SetSize();
|
||||||
|
|
||||||
fDrawIcon = true;
|
fDrawIcon = true;
|
||||||
Invalidate();
|
Invalidate();
|
||||||
return true;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
void
|
||||||
IconView::DrawIcon(bool draw)
|
IconView::DrawIcon(bool draw)
|
||||||
{
|
{
|
||||||
bool prev = fDrawIcon;
|
if (draw == fDrawIcon)
|
||||||
fDrawIcon = draw;
|
return;
|
||||||
if (prev != fDrawIcon)
|
|
||||||
Invalidate();
|
|
||||||
|
|
||||||
return prev;
|
fDrawIcon = draw;
|
||||||
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
IconView::Draw(BRect area)
|
IconView::Draw(BRect area)
|
||||||
{
|
{
|
||||||
SetDrawingMode(B_OP_ALPHA);
|
if (fDrawIcon && fIconBitmap != NULL) {
|
||||||
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
|
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
||||||
if (fDrawIcon)
|
|
||||||
DrawBitmap(fIconBitmap);
|
DrawBitmap(fIconBitmap);
|
||||||
|
SetDrawingMode(B_OP_COPY);
|
||||||
SetDrawingMode(B_OP_COPY);
|
} else
|
||||||
|
BView::Draw(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
IconView::InitCheck() const
|
||||||
|
{
|
||||||
|
if (fIconBitmap == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
return fIconBitmap->InitCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
IconView::_SetSize()
|
||||||
|
{
|
||||||
|
SetExplicitMinSize(BSize(fIconSize, fIconSize));
|
||||||
|
SetExplicitMaxSize(BSize(fIconSize, fIconSize));
|
||||||
|
SetExplicitPreferredSize(BSize(fIconSize, fIconSize));
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
#include <Button.h>
|
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
@@ -182,11 +181,10 @@ DataTranslationsWindow::_SetupViews()
|
|||||||
B_ALIGN_USE_FULL_HEIGHT));
|
B_ALIGN_USE_FULL_HEIGHT));
|
||||||
|
|
||||||
// Add the translator icon view
|
// Add the translator icon view
|
||||||
fIconView = new IconView(BRect(0, 0, 31, 31), B_TRANSLATE("Icon"),
|
fIconView = new IconView();
|
||||||
B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_FRAME_EVENTS);
|
|
||||||
|
|
||||||
// Add the translator info button
|
// Add the translator info button
|
||||||
BButton* button = new BButton("STD", B_TRANSLATE("Info" B_UTF8_ELLIPSIS),
|
fButton = new BButton("info", B_TRANSLATE("Info" B_UTF8_ELLIPSIS),
|
||||||
new BMessage(kMsgTranslatorInfo), B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
|
new BMessage(kMsgTranslatorInfo), B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
|
||||||
|
|
||||||
// Populate the translators list view
|
// Populate the translators list view
|
||||||
@@ -201,7 +199,7 @@ DataTranslationsWindow::_SetupViews()
|
|||||||
.SetInsets(0, 0, 0, 0)
|
.SetInsets(0, 0, 0, 0)
|
||||||
.Add(fRightBox, 0, 0, 3, 1)
|
.Add(fRightBox, 0, 0, 3, 1)
|
||||||
.Add(fIconView, 0, 1)
|
.Add(fIconView, 0, 1)
|
||||||
.Add(button, 2, 1);
|
.Add(fButton, 2, 1);
|
||||||
|
|
||||||
fTranslatorListView->MakeFocus();
|
fTranslatorListView->MakeFocus();
|
||||||
fTranslatorListView->Select(0);
|
fTranslatorListView->Select(0);
|
||||||
@@ -291,6 +289,7 @@ DataTranslationsWindow::MessageReceived(BMessage* message)
|
|||||||
if (selected < 0) {
|
if (selected < 0) {
|
||||||
// If none selected, clear the old one
|
// If none selected, clear the old one
|
||||||
fIconView->DrawIcon(false);
|
fIconView->DrawIcon(false);
|
||||||
|
fButton->SetEnabled(false);
|
||||||
fRightBox->RemoveChild(fConfigView);
|
fRightBox->RemoveChild(fConfigView);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -307,6 +306,7 @@ DataTranslationsWindow::MessageReceived(BMessage* message)
|
|||||||
BPath path;
|
BPath path;
|
||||||
_GetTranslatorInfo(item->ID(), name, info, version, path);
|
_GetTranslatorInfo(item->ID(), name, info, version, path);
|
||||||
fIconView->SetIcon(path);
|
fIconView->SetIcon(path);
|
||||||
|
fButton->SetEnabled(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
|
#include <Button.h>
|
||||||
#include <IconView.h>
|
#include <IconView.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
@@ -41,6 +42,7 @@ private:
|
|||||||
BBox* fRightBox;
|
BBox* fRightBox;
|
||||||
BView* fConfigView;
|
BView* fConfigView;
|
||||||
IconView* fIconView;
|
IconView* fIconView;
|
||||||
|
BButton* fButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user