Lyrics: Custom popup menu, default no transparency
This commit is contained in:
parent
50914809b6
commit
551fcb8c71
|
@ -8,20 +8,89 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include <Dragger.h>
|
#include <Dragger.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <TextView.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include "Song.h"
|
#include "Song.h"
|
||||||
|
|
||||||
|
|
||||||
|
LyricsTextView::LyricsTextView(BRect frame, const char* name, BRect textFrame,
|
||||||
|
uint32 resize, uint32 flags)
|
||||||
|
:
|
||||||
|
BTextView(frame, name, textFrame, resize, flags)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LyricsTextView::LyricsTextView(BMessage* data)
|
||||||
|
:
|
||||||
|
BTextView(data)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
LyricsTextView::Archive(BMessage* data, bool deep) const
|
||||||
|
{
|
||||||
|
status_t status = BTextView::Archive(data, deep);
|
||||||
|
data->AddString("class", "LyricsTextView");
|
||||||
|
data->AddString("add_on", "application/x-vnd.mediamonitor");
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LyricsTextView*
|
||||||
|
LyricsTextView::Instantiate(BMessage* data)
|
||||||
|
{
|
||||||
|
if (!validate_instantiation(data, "LyricsTextView"))
|
||||||
|
return NULL;
|
||||||
|
return new LyricsTextView(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LyricsTextView::MouseDown(BPoint where)
|
||||||
|
{
|
||||||
|
uint32 buttons = 0;
|
||||||
|
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
||||||
|
|
||||||
|
if (buttons & B_SECONDARY_MOUSE_BUTTON)
|
||||||
|
_RightClickPopUp(where)->Go(ConvertToScreen(where), true, false);
|
||||||
|
else
|
||||||
|
BTextView::MouseDown(where);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BPopUpMenu*
|
||||||
|
LyricsTextView::_RightClickPopUp(BPoint where)
|
||||||
|
{
|
||||||
|
BPopUpMenu* menu = new BPopUpMenu("rightClickPopUp");
|
||||||
|
BMenuItem* copy =
|
||||||
|
new BMenuItem("Copy", new BMessage(B_COPY), 'C', B_COMMAND_KEY);
|
||||||
|
BMenuItem* selectAll = new BMenuItem("Select all",
|
||||||
|
new BMessage(B_SELECT_ALL), 'A', B_COMMAND_KEY);
|
||||||
|
|
||||||
|
int32 start = -1, end = -1;
|
||||||
|
GetSelection(&start, &end);
|
||||||
|
|
||||||
|
copy->SetEnabled(start >= 0 && end > 0);
|
||||||
|
copy->SetTarget(this);
|
||||||
|
menu->AddItem(copy);
|
||||||
|
|
||||||
|
selectAll->SetTarget(this);
|
||||||
|
menu->AddItem(selectAll);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LyricsView::LyricsView(BRect frame)
|
LyricsView::LyricsView(BRect frame)
|
||||||
:
|
:
|
||||||
BView(frame, "Lyrics", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_TRANSPARENT_BACKGROUND | B_PULSE_NEEDED)
|
BView(frame, "Lyrics", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_TRANSPARENT_BACKGROUND | B_PULSE_NEEDED)
|
||||||
{
|
{
|
||||||
fFgColor = ui_color(B_PANEL_TEXT_COLOR);
|
|
||||||
fBgColor = ui_color(B_PANEL_BACKGROUND_COLOR);
|
|
||||||
|
|
||||||
BRect dragRect(0, 0, 10, frame.Height());
|
BRect dragRect(0, 0, 10, frame.Height());
|
||||||
BDragger* airdrag = new BDragger(dragRect, this,
|
BDragger* airdrag = new BDragger(dragRect, this,
|
||||||
B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
|
B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
|
||||||
|
@ -29,16 +98,20 @@ LyricsView::LyricsView(BRect frame)
|
||||||
AddChild(airdrag);
|
AddChild(airdrag);
|
||||||
|
|
||||||
BRect textRect(0, 0, Bounds().Width(), Bounds().Height() - 10);
|
BRect textRect(0, 0, Bounds().Width(), Bounds().Height() - 10);
|
||||||
fTextView = new BTextView(textRect, "lyricsText", textRect,
|
fTextView = new LyricsTextView(textRect, "lyricsText", textRect,
|
||||||
B_FOLLOW_ALL, B_WILL_DRAW);
|
B_FOLLOW_ALL, B_WILL_DRAW);
|
||||||
fTextView->MakeEditable(false);
|
fTextView->MakeEditable(false);
|
||||||
fTextView->SetStylable(false);
|
fTextView->SetStylable(true);
|
||||||
|
|
||||||
fScrollView = new BScrollView("scrollView", fTextView, B_FOLLOW_ALL_SIDES,
|
fScrollView = new BScrollView("scrollView", fTextView, B_FOLLOW_ALL_SIDES,
|
||||||
B_WILL_DRAW, false, true, B_NO_BORDER);
|
B_WILL_DRAW, false, true, B_NO_BORDER);
|
||||||
fScrollView->ScrollBar(B_VERTICAL)->Hide();
|
fScrollView->ScrollBar(B_VERTICAL)->Hide();
|
||||||
AddChild(fScrollView);
|
AddChild(fScrollView);
|
||||||
|
|
||||||
|
fTransparentInactivity = false;
|
||||||
|
fFgColor = ui_color(B_PANEL_TEXT_COLOR);
|
||||||
|
fBgColor = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||||
|
|
||||||
_Init(frame);
|
_Init(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,13 +120,15 @@ LyricsView::LyricsView(BMessage* data)
|
||||||
:
|
:
|
||||||
BView(data)
|
BView(data)
|
||||||
{
|
{
|
||||||
|
fTransparentInactivity = false;
|
||||||
fFgColor = ui_color(B_PANEL_TEXT_COLOR);
|
fFgColor = ui_color(B_PANEL_TEXT_COLOR);
|
||||||
fBgColor = ui_color(B_PANEL_BACKGROUND_COLOR);
|
fBgColor = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||||
|
|
||||||
fTextView = dynamic_cast<BTextView*>(FindView("lyricsText"));
|
fTextView = dynamic_cast<LyricsTextView*>(FindView("lyricsText"));
|
||||||
fScrollView = dynamic_cast<BScrollView*>(FindView("scrollView"));
|
fScrollView = dynamic_cast<BScrollView*>(FindView("scrollView"));
|
||||||
data->FindColor("background_color", &fBgColor);
|
data->FindColor("background_color", &fBgColor);
|
||||||
data->FindColor("foreground_color", &fFgColor);
|
data->FindColor("foreground_color", &fFgColor);
|
||||||
|
data->FindBool("transparent_inactivity", &fTransparentInactivity);
|
||||||
|
|
||||||
_Init(Frame());
|
_Init(Frame());
|
||||||
}
|
}
|
||||||
|
@ -65,6 +140,7 @@ LyricsView::Archive(BMessage* data, bool deep) const
|
||||||
status_t status = BView::Archive(data, deep);
|
status_t status = BView::Archive(data, deep);
|
||||||
data->AddColor("background_color", fBgColor);
|
data->AddColor("background_color", fBgColor);
|
||||||
data->AddColor("foreground_color", fFgColor);
|
data->AddColor("foreground_color", fFgColor);
|
||||||
|
data->AddBool("transparent_inactivity", fTransparentInactivity);
|
||||||
|
|
||||||
data->AddString("class", "LyricsView");
|
data->AddString("class", "LyricsView");
|
||||||
data->AddString("add_on", "application/x-vnd.mediamonitor");
|
data->AddString("add_on", "application/x-vnd.mediamonitor");
|
||||||
|
@ -119,7 +195,7 @@ LyricsView::Pulse()
|
||||||
_SetText(lyrics.String());
|
_SetText(lyrics.String());
|
||||||
} else if (path.IsEmpty() == true && path != fCurrentPath) {
|
} else if (path.IsEmpty() == true && path != fCurrentPath) {
|
||||||
fCurrentPath = path;
|
fCurrentPath = path;
|
||||||
_SetText(NULL);
|
_ClearText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +203,7 @@ LyricsView::Pulse()
|
||||||
void
|
void
|
||||||
LyricsView::_Init(BRect frame)
|
LyricsView::_Init(BRect frame)
|
||||||
{
|
{
|
||||||
_SetText(NULL);
|
_ClearText();
|
||||||
_UpdateColors();
|
_UpdateColors();
|
||||||
Pulse();
|
Pulse();
|
||||||
}
|
}
|
||||||
|
@ -136,15 +212,22 @@ LyricsView::_Init(BRect frame)
|
||||||
void
|
void
|
||||||
LyricsView::_SetText(const char* text)
|
LyricsView::_SetText(const char* text)
|
||||||
{
|
{
|
||||||
if (text != NULL) {
|
if (fScrollView->IsHidden() == true)
|
||||||
if (fTextView->IsHidden() == true)
|
fScrollView->Show();
|
||||||
fTextView->Show();
|
|
||||||
fTextView->SetText(text);
|
fTextView->SetText(text);
|
||||||
} else if (text == NULL) {
|
fTextView->SetAlignment(B_ALIGN_LEFT);
|
||||||
if (fTextView->IsHidden() == false)
|
}
|
||||||
fTextView->Hide();
|
|
||||||
fTextView->SetText("");
|
|
||||||
}
|
void
|
||||||
|
LyricsView::_ClearText()
|
||||||
|
{
|
||||||
|
if (fScrollView->IsHidden() == false && fTransparentInactivity == true)
|
||||||
|
fScrollView->Hide();
|
||||||
|
|
||||||
|
fTextView->SetText("No lyrics to display!");
|
||||||
|
fTextView->SetAlignment(B_ALIGN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,26 @@
|
||||||
#ifndef LYRICSVIEW_H
|
#ifndef LYRICSVIEW_H
|
||||||
#define LYRICSVIEW_H
|
#define LYRICSVIEW_H
|
||||||
|
|
||||||
#include <View.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
|
class BPopUpMenu;
|
||||||
class BScrollView;
|
class BScrollView;
|
||||||
class BTextView;
|
|
||||||
|
|
||||||
|
class LyricsTextView : public BTextView {
|
||||||
|
public:
|
||||||
|
LyricsTextView(BRect frame, const char* name, BRect textFrame,
|
||||||
|
uint32 resize, uint32 flags);
|
||||||
|
LyricsTextView(BMessage* archive);
|
||||||
|
|
||||||
|
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||||
|
static LyricsTextView* Instantiate(BMessage* data);
|
||||||
|
|
||||||
|
virtual void MouseDown(BPoint where);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BPopUpMenu* _RightClickPopUp(BPoint where);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class LyricsView : public BView {
|
class LyricsView : public BView {
|
||||||
|
@ -20,21 +36,23 @@ public:
|
||||||
static LyricsView* Instantiate(BMessage* data);
|
static LyricsView* Instantiate(BMessage* data);
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
|
|
||||||
virtual void Pulse();
|
virtual void Pulse();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Init(BRect frame);
|
void _Init(BRect frame);
|
||||||
|
|
||||||
void _InitInterface();
|
|
||||||
void _SetText(const char* text);
|
void _SetText(const char* text);
|
||||||
|
void _ClearText();
|
||||||
|
|
||||||
void _UpdateColors();
|
void _UpdateColors();
|
||||||
|
|
||||||
BString _GetCurrentPath();
|
BString _GetCurrentPath();
|
||||||
|
|
||||||
BTextView* fTextView;
|
LyricsTextView* fTextView;
|
||||||
BScrollView* fScrollView;
|
BScrollView* fScrollView;
|
||||||
|
|
||||||
|
bool fTransparentInactivity;
|
||||||
|
|
||||||
rgb_color fBgColor;
|
rgb_color fBgColor;
|
||||||
rgb_color fFgColor;
|
rgb_color fFgColor;
|
||||||
BString fCurrentPath;
|
BString fCurrentPath;
|
||||||
|
|
Ŝarĝante…
Reference in New Issue