Make the "no preview" screen work in all cases

* HideNoPreview() was never called...
* Use a BCardLayout to make it easier to know which of the two screens
is shown.
This commit is contained in:
Adrien Destugues
2014-08-14 12:38:48 +02:00
parent 613468813b
commit 9bac05ae6c
2 changed files with 25 additions and 20 deletions
+20 -17
View File
@@ -12,6 +12,7 @@
#include <iostream> #include <iostream>
#include <CardLayout.h>
#include <Catalog.h> #include <Catalog.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <Point.h> #include <Point.h>
@@ -65,6 +66,21 @@ PreviewView::PreviewView(const char* name)
// We draw the "monitor" around the preview, hence the strange insets. // We draw the "monitor" around the preview, hence the strange insets.
layout->SetInsets(10, 8, 11, 16); layout->SetInsets(10, 8, 11, 16);
SetLayout(layout); SetLayout(layout);
fNoPreview = new BStringView("no preview",
B_TRANSLATE("No preview available"));
fNoPreview->Hide();
BView* container = new BView("preview container", 0);
container->SetLayout(new BCardLayout());
AddChild(container);
container->SetViewColor(0, 0, 0);
container->SetLowColor(0, 0, 0);
container->AddChild(fNoPreview);
fNoPreview->SetHighColor(255, 255, 255);
fNoPreview->SetAlignment(B_ALIGN_CENTER);
} }
@@ -110,7 +126,7 @@ PreviewView::AddPreview()
fSaverView = new BView("preview", B_WILL_DRAW); fSaverView = new BView("preview", B_WILL_DRAW);
fSaverView->SetViewColor(0, 0, 0); fSaverView->SetViewColor(0, 0, 0);
fSaverView->SetLowColor(0, 0, 0); fSaverView->SetLowColor(0, 0, 0);
AddChild(fSaverView); ChildAt(0)->AddChild(fSaverView);
float aspectRatio = 4.0f / 3.0f; float aspectRatio = 4.0f / 3.0f;
// 4:3 monitor // 4:3 monitor
@@ -120,20 +136,9 @@ PreviewView::AddPreview()
fSaverView->SetExplicitSize(BSize(previewWidth, previewHeight)); fSaverView->SetExplicitSize(BSize(previewWidth, previewHeight));
fSaverView->ResizeTo(previewWidth, previewHeight); fSaverView->ResizeTo(previewWidth, previewHeight);
fNoPreview = new BStringView("no preview",
B_TRANSLATE("No preview available"));
fNoPreview->Hide();
fNoPreview->SetExplicitSize(BSize(previewWidth, previewHeight)); fNoPreview->SetExplicitSize(BSize(previewWidth, previewHeight));
fNoPreview->ResizeTo(previewWidth, previewHeight); fNoPreview->ResizeTo(previewWidth, previewHeight);
AddChild(fNoPreview);
fNoPreview->SetViewColor(0, 0, 0);
fNoPreview->SetLowColor(0, 0, 0);
fNoPreview->SetHighColor(255, 255, 255);
fNoPreview->SetAlignment(B_ALIGN_CENTER);
return fSaverView; return fSaverView;
} }
@@ -142,7 +147,7 @@ BView*
PreviewView::RemovePreview() PreviewView::RemovePreview()
{ {
if (fSaverView != NULL) if (fSaverView != NULL)
RemoveChild(fSaverView); ChildAt(0)->RemoveChild(fSaverView);
BView* saverView = fSaverView; BView* saverView = fSaverView;
fSaverView = NULL; fSaverView = NULL;
@@ -160,14 +165,12 @@ PreviewView::SaverView()
void void
PreviewView::ShowNoPreview() const PreviewView::ShowNoPreview() const
{ {
fSaverView->Hide(); ((BCardLayout*)ChildAt(0)->GetLayout())->SetVisibleItem((int32)0);
fNoPreview->Show();
} }
void void
PreviewView::HideNoPreview() const PreviewView::HideNoPreview() const
{ {
fNoPreview->Hide(); ((BCardLayout*)ChildAt(0)->GetLayout())->SetVisibleItem(1);
fSaverView->Show();
} }
@@ -828,11 +828,13 @@ ModulesView::_OpenSaver()
BScreenSaver* saver = ScreenSaver(); BScreenSaver* saver = ScreenSaver();
if (saver != NULL && fSettingsView != NULL) { if (saver != NULL && fSettingsView != NULL) {
saver->StartConfig(fSettingsView); saver->StartConfig(fSettingsView);
if (saver->StartSaver(view, true) == B_OK) if (saver->StartSaver(view, true) == B_OK) {
fPreviewView->HideNoPreview();
fSaverRunner->Run(); fSaverRunner->Run();
else } else
fPreviewView->ShowNoPreview(); fPreviewView->ShowNoPreview();
} } else
fPreviewView->ShowNoPreview();
if (fSettingsView->ChildAt(0) == NULL) { if (fSettingsView->ChildAt(0) == NULL) {
// There are no settings at all, we add the module name here to // There are no settings at all, we add the module name here to