TilePICoutix

git-svn-id: svn://db.shs.com.ru/pip@45 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-03-30 11:23:13 +00:00
parent 595543bea9
commit 0cb2b20d2e
11 changed files with 75 additions and 19 deletions

View File

@@ -19,7 +19,7 @@ class Catcher: public PIObject {
PIOBJECT(Catcher)
public:
EVENT_HANDLER2(void, event, PIScreenTile *, t, PIScreenTypes::TileEvent, e) {
piCout << "event from" << t->name << "type" << e.type << e.data;
piCout << "event from" << t->name() << "type" << e.type << e.data;
if (e.data == 2)
delete t->parentTile();
}

View File

@@ -496,7 +496,7 @@ void PIScreen::end() {
PIScreenTile * PIScreen::tileByName(const PIString & name) {
PIVector<PIScreenTile*> tl(tiles());
piForeach (PIScreenTile * t, tl)
if (t->name == name)
if (t->name() == name)
return t;
return 0;
}

View File

@@ -48,8 +48,7 @@
using namespace PIScreenTypes;
PIScreenTile::PIScreenTile(const PIString & n, Direction d, SizePolicy p) {
name = n;
PIScreenTile::PIScreenTile(const PIString & n, Direction d, SizePolicy p): PIObject(n) {
direction = d;
size_policy = p;
focus_flags = 0;

View File

@@ -28,8 +28,9 @@
class PIScreenDrawer;
class PIScreenTile {
class PIScreenTile: public PIObject {
friend class PIScreen;
PIOBJECT_SUBCLASS(PIScreenTile, PIObject)
public:
PIScreenTile(const PIString & n = PIString(), PIScreenTypes::Direction d = PIScreenTypes::Vertical, PIScreenTypes::SizePolicy p = PIScreenTypes::Preferred);
virtual ~PIScreenTile();
@@ -45,7 +46,6 @@ public:
void setMargins(int m) {marginLeft = marginRight = marginTop = marginBottom = m;}
void setMargins(int l, int r, int t, int b) {marginLeft = l; marginRight = r; marginTop = t; marginBottom = b;}
PIString name;
PIScreenTypes::Direction direction;
PIScreenTypes::SizePolicy size_policy;
PIScreenTypes::FocusFlags focus_flags;

View File

@@ -383,3 +383,40 @@ void TileProgress::drawEvent(PIScreenDrawer * d) {
d->drawText(x + sx + fw, y, s.cutLeft(fw), Black, Transparent);
}
}
TilePICout::TilePICout(const PIString & n): TileList(n) {
max_lines = 1024;
selection_mode = TileList::SingleSelection;
PICout::setBufferActive(true);
}
void TilePICout::drawEvent(PIScreenDrawer * d) {
PIString out = PICout::buffer(true);
if (!out.isEmpty()) {
PIStringList l = out.split("\n");
bool scroll = (cur == content.size_s() - 1) || !has_focus;
piForeachC (PIString & s, l)
content << TileList::Row(s, format);
if (content.size_s() > max_lines)
content.remove(0, content.size_s() - max_lines);
if (scroll) {
offset = piMaxi(0, content.size_s() - lhei);
cur = content.size_s() - 1;
}
}
TileList::drawEvent(d);
}
bool TilePICout::keyEvent(PIKbdListener::KeyEvent key) {
if (key.key == 'C') {
content.clear();
cur = offset = 0;
return true;
}
return TileList::keyEvent(key);
}

View File

@@ -53,7 +53,7 @@ public:
RowPressed
};
typedef PIPair<PIString, PIScreenTypes::CellFormat> Row;
PIVector<Row> content;
PIDeque<Row> content;
PIScreenTypes::Alignment alignment;
SelectionMode selection_mode;
PISet<int> selected;
@@ -135,4 +135,17 @@ protected:
};
class TilePICout: public TileList {
public:
TilePICout(const PIString & n = PIString());
PIScreenTypes::CellFormat format;
int max_lines;
protected:
void drawEvent(PIScreenDrawer * d);
bool keyEvent(PIKbdListener::KeyEvent key);
};
#endif // PISCREENTILES_H

View File

@@ -181,6 +181,9 @@ public:
//! Returns if %PIEthernet connected to TCP server. Use only for TCP_Client
bool isConnected() const {return connected_;}
//! Returns if %PIEthernet is connecting to TCP server. Use only for TCP_Client
bool isConnecting() const {return connecting_;}
//! Start listen for incoming TCP connections on address \a readAddress(). Use only for TCP_Server
bool listen(bool threaded = false);

View File

@@ -314,12 +314,12 @@ bool PIPeer::dataRead(uchar * readed, int size) {
if (type != 4) return true;
diag_d.received(size);
ba >> from >> to >> cnt >> rec_size;
//piCout << "[PIPeer \"" + name_ + "\"] Received packet" << /*type << from << to << cnt <<*/ rec_size;
piCoutObj << "Received packet" << type << from << to << cnt << rec_size;
if (type == 4) { // data packet
if (to == self_info.name) { // my packet
int msg_count, cmsg;
ba >> msg_count >> cmsg;
//piCout << "[PIPeer \"" + name_ + "\"] Received packet" << type << from << to << cnt << rec_size << msg_count << cmsg;
piCoutObj << "Received packet" << type << from << to << cnt << rec_size << msg_count << cmsg;
if (cmsg == 0 && msg_count == 1) {
dataReceived(from, ba);
dataReceivedEvent(from, ba);
@@ -333,11 +333,11 @@ bool PIPeer::dataRead(uchar * readed, int size) {
}
PeerData & pd(fp->_data);
if (cmsg == 0) {
//piCout << "[PIPeer \"" + name_ + "\"] Packet clear" << rec_size;
piCoutObj << "Packet clear" << rec_size;
pd.clear();
pd.msg_count = msg_count;
}
//piCout << "[PIPeer \"" + name_ + "\"] Packet add" << cmsg << ba.size_s();
piCoutObj << "Packet add" << cmsg << ba.size_s();
pd.addData(ba);
bool frec = pd.isFullReceived();
PIByteArray rba(pd.data);
@@ -345,7 +345,7 @@ bool PIPeer::dataRead(uchar * readed, int size) {
if (frec) {
dataReceived(from, rba);
dataReceivedEvent(from, rba);
//piCout << "[PIPeer \"" + name_ + "\"] Packet received" << pd.data.size_s();
piCoutObj << "Packet received" << pd.data.size_s();
}
return true;
}

View File

@@ -267,7 +267,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
Remote * r(0);
PIString dir;
int type; ba >> type;
//std::cout << "rec from " << from << type;
//piCout << "rec from " << from << type;
switch (type) {
case RequestHostInfo:
makeMyHostInfo();

View File

@@ -177,7 +177,7 @@ FileManager::FileManager(Daemon * d) {
panels[i] = new TileDir();
panels[i]->fm = this;
panels[i]->key_func = (void*)tileKey_s;
panels[i]->name = "file panel " + PIString(i);
panels[i]->setName("file panel " + PIString(i));
panels[i]->label_path = plabel;
panel->addTile(plabel);
panel->addTile(panels[i]);

View File

@@ -55,25 +55,29 @@ public:
screen.rootTile()->addTile(center);
PIScreenTile * mt = tmenu = menuTile();
mt->show(); mt->name = "main menu";
mt->show(); mt->name() = "main menu";
center->addTile(mt); mtiles << mt;
mt = tinfo = infoTile();
mt->hide(); mt->name = "local info";
mt->hide(); mt->name() = "local info";
center->addTile(mt); mtiles << mt;
mt = tfm = file_manager.tile();
mt->hide(); mt->name = "file manager";
mt->hide(); mt->name() = "file manager";
center->addTile(mt); mtiles << mt;
mt = tdaemon = daemon_.tile();
mt->hide(); mt->name = "daemon";
mt->hide(); mt->name() = "daemon";
center->addTile(mt); mtiles << mt;
mt = tpeer = peerTile();
mt->hide(); mt->name = "peer info";
mt->hide(); mt->name() = "peer info";
center->addTile(mt); mtiles << mt;
TilePICout * outt = new TilePICout();
outt->size_policy = PIScreenTypes::Expanding;
screen.rootTile()->addTile(outt);
CONNECTU(&screen, tileEvent, this, tileEvent)
CONNECTU(&screen, keyPressed, this, keyEvent)
CONNECTU(&file_manager, menuRequest, this, menuRequest)